Bug 2017285

Summary: jq try/catch stops iteration over items
Product: [Fedora] Fedora Reporter: WRH <wil.rh>
Component: jqAssignee: Haïkel Guémar <karlthered>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 34CC: bhills, davide, david, fpercoco, karlthered, lhh, thalman
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: jq-1.6-13.fc37 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2049594 2049601 (view as bug list) Environment:
Last Closed: 2022-03-11 18:56:06 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2045178, 2049594, 2049601    

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.