1
1
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:
Mattias Wadman 2023-10-20 14:03:52 +02:00
parent 5b9c902949
commit 45a8dd9c74
2 changed files with 12 additions and 3 deletions

View File

@ -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: \(.)");

View File

@ -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