Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try/catch doesn't work with field updates #2230

Closed
burtgulash opened this issue Dec 17, 2020 · 3 comments
Closed

Try/catch doesn't work with field updates #2230

burtgulash opened this issue Dec 17, 2020 · 3 comments

Comments

@burtgulash
Copy link

Describe the bug
try/catch doesn't seem to be working well with field updates.

To Reproduce
% echo '{"x":"123"}' | jq -c '.x = (.x | try tonumber catch "error")'
{"x":123}
% echo '{"x":"123"}' | jq -c '.x |= (try tonumber catch "error")'
{"x":"error"}

Environment (please complete the following information):
% jq --version
jq-1.6

@odnoletkov
Copy link

Seems like a duplicate of #2220 and #2140

@itchyny
Copy link
Contributor

itchyny commented Dec 18, 2020

And this is already fixed in the master version.

 % jq --version
jq-master-a17dd32

 % echo '{"x":"123"}' | jq -c '.x = (.x | try tonumber catch "error")'
{"x":123}

 % echo '{"x":"123"}' | jq -c '.x |= (try tonumber catch "error")'
{"x":123}

@emanuele6
Copy link
Member

jq 1.7 released with the fix.

$ jq --version
jq-1.7
$ echo '{"x":"123"}' | jq -c '.x = (.x | try tonumber catch "error")'
{"x":123}
$ echo '{"x":"123"}' | jq -c '.x |= (try tonumber catch "error")'
{"x":123}

closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants