1
1
mirror of https://github.com/wader/fq.git synced 2024-11-26 21:55:57 +03:00

Merge pull request #788 from wader/from_jq-better-error

interp: Better from_jq error handling
This commit is contained in:
Mattias Wadman 2023-10-20 14:39:44 +02:00 committed by GitHub
commit 677c7e4258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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