Bug 2049601

Summary: jq try/catch stops iteration over items
Product: Red Hat Enterprise Linux 8 Reporter: Tomas Halman <thalman>
Component: jqAssignee: Tomas Halman <thalman>
Status: CLOSED ERRATA QA Contact: Scott Poore <spoore>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 8.6CC: aboscatt, bhills, david, extras-qa, karlthered, lhh, spoore, thalman, wil.rh
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: jq-1.6-4.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 2017285 Environment:
Last Closed: 2023-05-16 08:27:08 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: 2017285    
Bug Blocks: 2049594    

Description Tomas Halman 2022-02-02 12:33:32 UTC
+++ This bug was initially created as a clone of Bug #2017285 +++

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

--- Additional comment from Tomas Halman on 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.

--- Additional comment from Tomas Halman on 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

--- Additional comment from Tomas Halman on 2022-02-02 12:15:31 UTC ---

The issue can be also avoided by providing `--disable-decnum` configure option

HTH
T.

Comment 1 Tomas Halman 2022-06-06 10:12:29 UTC
Patch has been accepted (https://github.com/stedolan/jq/pull/2400).

Comment 5 Scott Poore 2022-11-01 21:24:32 UTC
Verified

Version ::

jq-1.6-5.el8.x86_64

Results ::

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

Comment 8 errata-xmlrpc 2023-05-16 08:27:08 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (jq bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:2778