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

Halt does not terminate jq #2368

Closed
smac89 opened this issue Nov 9, 2021 · 3 comments
Closed

Halt does not terminate jq #2368

smac89 opened this issue Nov 9, 2021 · 3 comments
Labels

Comments

@smac89
Copy link

smac89 commented Nov 9, 2021

Describe the bug
From the v1.6 jq docs, it says that halt does the following:

Stops the jq program with no further outputs. jq will exit with exit status 0

However, from my testing of both halt and halt_error, neither of them causes jq to terminate with no further outputs.

To Reproduce
Input:

{"value":{"error":"no such element","message":"no such element: xxx"}}
{"value":null}

Command:

jq '.value | if .error then "\(.message)\n" | halt_error(1) else "" end'

Output:

no such element: xxx
""

Expected behavior
There should only be one output, seeing as after reading the first object, it causes halt_error to run

Environment (please complete the following information):

Distributor ID: Ubuntu
Description:    Ubuntu 21.10
Release:        21.10
Codename:       impish
  • jq version 1.6

Additional context

@smac89
Copy link
Author

smac89 commented Nov 9, 2021

Just as I posted this, I found a solution here. However, I think the docs need to be expanded on those two functions (halt, and halt_error) to explain that they only work when jq is run with -n.

@pkoppstein
Copy link
Contributor

@smac89 - The issue you raise could be regarded entirely as a documentation issue. Indeed, the jq developers have generally been quite definite about not wanting to break the stream-processing character of jq - i.e., assuming that input has not been "slurped", and that each input is well-formed, each input is processed separately.

@itchyny
Copy link
Contributor

itchyny commented Jul 11, 2023

This has been resolved by #2667.

@itchyny itchyny closed this as completed Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants