-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
Describe the bug
try
/catch
produce unexpected results when used in the rhs of the update assignment |=
To Reproduce
$ jq -n '1 | . |= 2' # OK
2
$ jq -n '1 | . |= try 2' # BUG, expected: 2
null
$ jq -n '1 | . |= try 2 catch 3' # BUG, expected: 2
3
$ jq -n '1 | . |= try 2 catch .' # BUG, expected: 2
{
"__jq": 0
}
$ jq -n '["1", "2a", "3", 4] | .[] |= try tonumber' # BUG, expected: [1, null, 3, 4]
[
"2a",
4
]
Plain assignment =
and surprisingly even arithmetic update-assignments such as +=
work as expected:
$ jq -n '1 | . = try 2' # OK
2
$ jq -n '1 | . += try 2' # OK
3
Throwing the error also works as expected
$ jq -n '1 | . |= try error("err")' # OK
null
$ jq -n '1 | . |= try error("err") catch 2' # OK
2
Environment
% jq --version; uname; sw_vers -productVersion
jq-1.6
Darwin
10.15.7
$ jq --version; uname
jq-1.6
Linux
Metadata
Metadata
Assignees
Labels
No labels