-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
|=.? returns empty #2140
Comments
That's a known bug that I think is fixed on master. If you're able, can you try building master from source? |
@wtlangford Would you happen to have a link to the existing issue? I will close this as duplicate. |
Sure, it's issue #2011 |
This is a different issue and reproducible with the master version. % jq --version
jq-master-a17dd32
% jq -nc '{foo: "bar"} | .foo |= .?'
{}
% jq -nc '{foo: "bar"} | .foo |= ( .? // "baz" )'
{}
% jq -nc '{value: "[]"} | .value |= try fromjson catch .' # yes this works
{"value":[]} |
Tentatively reopening on the basis that Also thought I should include my 1.5 workaround in case some poor soul with a conservative distro finds this thread because of the
|
I think |
Alright, now we're talking! @itchyny please see this branch https://github.com/leonid-s-usov/jq/tree/bt_signalling I'm finishing some scope of work at my day job and then have the plan to get back on track with the changes mentioned. It's a bit ambitious, cause it involves the dlopen initiative of @nicowilliams , but we'll pull it out this summer, I believe |
Okay, thanks for explanation. I finally understand what #1859 (comment) means and it fixes various issues around this subject. |
Regarding % jq -n '[0] as [$x] ?// $x | $x[0]' # ok
0
% jq -n '[0] as [$x] ?// $x | $x | .[0]' # still the subsequent expression?
0
% jq -n '([0] as [$x] ?// $x | $x) | .[0]' # is this ok? or should be an error?
0
% jq -n '([0] as [$x] ?// $x | $x) | type | error' # should be number?
jq: error (at <unknown>): array
% jq -n '([2] as $x ?// [$x] | $x) * ([3] as $x ?// [$x] | $x)' # useful? or should be an error?
6 |
After encountering this error, I asked about it on Stackoverflow. One reply contained a link to this issue |
|
Close jqlang#1885, jqlang#2140, jqlang#2011, jqlang#2220, jqlang#2485, 2073 Rename the FORK_OPT opcode to TRY_BEGIN, add a TRY_END opcode, and wrap errors when raising through a TRY_END so that they will not be caught by the matching TRY_BEGIN. Now a `try exp catch handler` expression generates code like: TRY_BEGIN handler <exp> TRY_END JUMP past_handler handler: <handler> past_handler: ... On backtrack through TRY_BEGIN it just backtracks. If anything past the whole thing raises when <exp> produced a value, then the TRY_END will catch the error, wrap it in another, and backtrack. The TRY_BEGIN will see a wrapped error and then it will unwrap and re-raise the error. If <exp> raises, then TRY_BEGIN will catch the error and jump to the handler, but the TRY_BEGIN will not stack_save() in that case, so on raise/backtrack the TRY_BEGIN will not execute again (nor will the TRY_END).
Close #1885, #2140, #2011, #2220, #2485, #2073 Rename the FORK_OPT opcode to TRY_BEGIN, add a TRY_END opcode, and wrap errors when raising through a TRY_END so that they will not be caught by the matching TRY_BEGIN. Now a `try exp catch handler` expression generates code like: TRY_BEGIN handler <exp> TRY_END JUMP past_handler handler: <handler> past_handler: ... On backtrack through TRY_BEGIN it just backtracks. If anything past the whole thing raises when <exp> produced a value, then the TRY_END will catch the error, wrap it in another, and backtrack. The TRY_BEGIN will see a wrapped error and then it will unwrap and re-raise the error. If <exp> raises, then TRY_BEGIN will catch the error and jump to the handler, but the TRY_BEGIN will not stack_save() in that case, so on raise/backtrack the TRY_BEGIN will not execute again (nor will the TRY_END).
Thank you for this life-changing language. I regret that my first correspondence is a complaint.
Try-catch returns empty following filter assignment.
Input
Expected output
Actual output
Furthermore,
//
is unable to catch the result:Environment (please complete the following information):
This is an extremely minimized example; I'm actually trying to process incoming strings which may or may not contain valid JSON, as in
.value |= (fromjson? // .)
. I catch some undocumented error formatting when I try this:Thanks again for your efforts.
The text was updated successfully, but these errors were encountered: