Bug 2017285 - jq try/catch stops iteration over items
Summary: jq try/catch stops iteration over items
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: jq
Version: 34
Hardware: Unspecified
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Haïkel Guémar
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 2049594 2049601 2045178
TreeView+ depends on / blocked
 
Reported: 2021-10-26 08:30 UTC by WRH
Modified: 2022-03-11 18:56 UTC (History)
7 users (show)

Fixed In Version: jq-1.6-13.fc37
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 2049594 2049601 (view as bug list)
Environment:
Last Closed: 2022-03-11 18:56:06 UTC
Type: Bug


Attachments (Terms of Use)

Description WRH 2021-10-26 08:30:34 UTC
Description of problem:

An error raised and caught during an iteration appears to interrupt the iteration. 
In the example below the intent is to convert all "strings" into "numbers" when they can be and to ignore all other values.


Version-Release number of selected component (if applicable):
jq-1.6-10.fc34.x86_64

How reproducible:
every time

Steps to Reproduce:
1. `jq '.[]| tonumber? ' <<< '["1", "2", "a", "3"]'`

Actual results:
```
1
2
```


Expected results:

```
1
2
3
```


Additional info:
Problem seems to have appeared with 1.6-10

Comment 1 Tomas Halman 2022-01-11 18:07:53 UTC
This issue has been introduced in commit https://github.com/stedolan/jq/commit/cf4b48c7ba30cb30e116b523cff036ea481459f

It is not fixed upstream yet.

Comment 2 Tomas Halman 2022-01-20 10:23:42 UTC
In fact `jq` does not stop iterrating, it just stops converting and printing strings

    jq '.[]| tonumber? ' <<< '["1", "a", "2", 3]'

will print 1 and 3 because 3 is not converted from string.

Here is the PR to discuss and find the fix: https://github.com/stedolan/jq/pull/2400

Tom

Comment 3 Tomas Halman 2022-02-02 12:15:31 UTC
The issue can be also avoided by providing `--disable-decnum` configure option

HTH
T.

Comment 4 Davide Cavalca 2022-03-08 20:57:00 UTC
I've put up https://src.fedoraproject.org/rpms/jq/pull-request/5 to address this.

Comment 5 Fedora Update System 2022-03-11 18:53:02 UTC
FEDORA-2022-4e51f14539 has been submitted as an update to Fedora 37. https://bodhi.fedoraproject.org/updates/FEDORA-2022-4e51f14539

Comment 6 Fedora Update System 2022-03-11 18:56:06 UTC
FEDORA-2022-4e51f14539 has been pushed to the Fedora 37 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.