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_error/1 difference and missing halt_error/0 #236

Open
wader opened this issue Nov 18, 2024 · 2 comments
Open

halt_error/1 difference and missing halt_error/0 #236

wader opened this issue Nov 18, 2024 · 2 comments

Comments

@wader
Copy link
Contributor

wader commented Nov 18, 2024

$ jq -n 'null | halt_error(5)'
$ jaq -n 'null | halt_error(5)'
null

Can't find this in documentation but there is a comment about in the code https://github.com/jqlang/jq/blob/master/src/main.c#L228-L229

Noticed this while messing with jqjq run-tests code.

Missing halt_error/0 is define liks this in jq:

def halt_error: halt_error(5);
@wader wader changed the title halt_error/1 difference and missing halt_error/0 halt_error/1 difference and missing halt_error/0 Nov 18, 2024
@01mf02
Copy link
Owner

01mf02 commented Nov 19, 2024

So what does the documentation say about halt_error/1?

Stops the jq program with no further outputs. The input will be printed on stderr as raw output (i.e., strings will not have double quotes) with no decoration, not even a newline.

How is null printed as raw output?

$ jq -rn 'null'
null

So jq -n 'null | halt_error' must print null too, if we follow the documentation. I think that it's better to follow the documentation here, as I find its behaviour simpler and less confusing. A user can always use something like if . == null then "" end | halt_error to get jq's behaviour.

@wader
Copy link
Contributor Author

wader commented Nov 19, 2024

I seems @nicowilliams wrote the "Halt with no output" comment for null, would be great to hear what he thinks or what the idea was? maybe @itchyny has some ideas also? fix jq or fix jq docs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants