jaq icon indicating copy to clipboard operation
jaq copied to clipboard

`halt_error/1` difference and missing `halt_error/0`

Open wader opened this issue 1 year ago • 2 comments

$ 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 avatar Nov 18 '24 14:11 wader

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.

01mf02 avatar Nov 19 '24 07:11 01mf02

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?

wader avatar Nov 19 '24 09:11 wader