mirror of
https://github.com/wader/fq.git
synced 2024-11-27 14:14:58 +03:00
interp: Better from_jq error handling
Thanks @emanuele6 for reporting
This commit is contained in:
parent
5b9c902949
commit
45a8dd9c74
@ -72,7 +72,10 @@ def from_jq:
|
||||
| if . == "TermTypeNull" then null
|
||||
elif . == "TermTypeTrue" then true
|
||||
elif . == "TermTypeFalse" then false
|
||||
elif . == "TermTypeString" then $v.term.str.str
|
||||
elif . == "TermTypeString" then
|
||||
if $v.term.str.queries then error("string interpolation")
|
||||
else $v.term.str.str
|
||||
end
|
||||
elif . == "TermTypeNumber" then $v.term.number | tonumber
|
||||
elif . == "TermTypeObject" then
|
||||
( $v.term.object.key_vals // []
|
||||
@ -87,10 +90,10 @@ def from_jq:
|
||||
( def _a: if .op then .left, .right | _a end;
|
||||
[$v.term.array.query // empty | _a | _f]
|
||||
)
|
||||
else error("unknown term")
|
||||
else error("unsupported term \($v.term.type)")
|
||||
end
|
||||
);
|
||||
try
|
||||
(_query_fromstring | _f)
|
||||
catch
|
||||
error("from_jq only supports constant literals");
|
||||
error("from_jq only supports constant literals: \(.)");
|
||||
|
6
format/json/testdata/jq.fqtest
vendored
6
format/json/testdata/jq.fqtest
vendored
@ -146,3 +146,9 @@ string
|
||||
{}
|
||||
{}
|
||||
----
|
||||
$ fq -i
|
||||
null> `"\(123)"` | from_jq
|
||||
error: from_jq only supports constant literals: string interpolation
|
||||
null> `if true then 123 else false end` | from_jq
|
||||
error: from_jq only supports constant literals: unsupported term TermTypeIf
|
||||
null> ^D
|
||||
|
Loading…
Reference in New Issue
Block a user