Skip to content

Commit

Permalink
cli: Make --argjson and --decode-file error similar
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Sep 12, 2021
1 parent 1d15c1d commit ec98fd3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 14 additions & 5 deletions pkg/interp/interp.jq
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,15 @@ def _main:
+ ( {
argjson: (
( $args_opts.argjson
| if . then map(
| if . then
map(
( . as $a
| .[1] |=
try fromjson
catch error("--argjson \($a[0]): \(.)")
try fromjson
catch
( "--argjson \($a[0]): \(.)"
| halt_error(_exit_code_args_error)
)
)
)
end
Expand All @@ -644,9 +648,14 @@ def _main:
decode_file: (
( $args_opts.decode_file
| if . then
( map(.[1] |=
map(
( . as $a
| .[1] |=
try (open | decode($args_opts.decode_format))
catch halt_error(_exit_code_args_error)
catch
( "--decode-file \($a[0]): \(.)"
| halt_error(_exit_code_args_error)
)
)
)
end
Expand Down
4 changes: 2 additions & 2 deletions pkg/interp/testdata/argvars.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ error: /nonexisting: file not found
$ fq -n --decode-file filea /nonexisting
exitcode: 2
stderr:
error: /nonexisting: file not found
error: --decode-file filea: /nonexisting: file not found
$ fq -n -d mp4 --decode-file filea /test.mp3 '$filea'
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f| |.: {} /test.mp3 (mp4)
| | | error: mp4: failed to validate at position 0x8: no styp, ftyp, free or moov box found
0x000|49 44 33 04 00 00 00 00 00 23 54 53 53 45 00 00|ID3......#TSSE..| unknown0: 49443304000000000023545353450000...
* |until 0x283.7 (end) (644) | |
$ fq -n --argjson a '(' '$a'
exitcode: 5
exitcode: 2
stderr:
error: --argjson a: invalid character '(' looking for beginning of value
$ fq -n --argjson a
Expand Down

0 comments on commit ec98fd3

Please sign in to comment.