mirror of
https://github.com/wader/fq.git
synced 2024-09-11 20:07:11 +03:00
Merge pull request #788 from wader/from_jq-better-error
interp: Better from_jq error handling
This commit is contained in:
commit
677c7e4258
@ -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