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

stderr doesn't print raw #2063

Closed
lhns opened this issue Feb 19, 2020 · 7 comments · Fixed by #2751
Closed

stderr doesn't print raw #2063

lhns opened this issue Feb 19, 2020 · 7 comments · Fixed by #2751
Labels
Milestone

Comments

@lhns
Copy link

lhns commented Feb 19, 2020

Describe the bug
stderr doesn't print its input as a raw string but as an escaped json string.

To Reproduce

jq -n '"line1\nline2" | stderr | empty'

Outputs "line1\nline2"

Expected behavior
As the manual states:

stderr
Prints its input in raw and compact mode to stderr with no additional decoration, not even a newline.

I expected the program to output be:

line1
line2

Environment (please complete the following information):

  • OS and Version: Redhat Enterprise Linux 6
  • jq version 1.6
@nicowilliams
Copy link
Contributor

This is not a bug, but a feature. Perhaps stderr should output raw when jq is in raw output mode, or perhaps we need a new rawstderr builtin. Or perhaps we can leave this to the I/O work we're doing, and then the user can open /dev/null in raw mode.

@ajasmin
Copy link
Contributor

ajasmin commented Dec 16, 2020

The documentation is somewhat misleading

stderr
Prints its input in raw and compact mode to stderr with no additional decoration, not even a newline.

Would let you believe that stderr behave like --raw-output and --compact-output. "Not even a new line" is where it differs from --compact-output.

Perhaps another word than "raw" could be used here?

@vergenzt
Copy link

vergenzt commented Nov 9, 2021

Yeah this is a bug IMO -- either the behavior or the documentation should be fixed, because right now they're inconsistent.

@hyperupcall
Copy link

hyperupcall commented Apr 13, 2022

I am really enjoying jq - unfortunately I tripped up on this as well

I perused the docs quite extensively and it seems there is no way to print an arbitrary string (with escape sequences) to standard error?

I can't use stderr because newlines of its input are automatically escaped. halt_error prints the way I want, but it halts the program. The only way I have been able to print a newline to stderr is through debug - its an unfortunate unaesthetic workaround, but it works.

I don't think that the behavior of stderr should change based on if jq is in raw mode. If it is not possible in one way or another to change stderr, I would welcome another function that yields the expected behavior.

@danfuzz
Copy link

danfuzz commented Jun 21, 2022

Just wanted to register a +1 on folks who have run into this surprising behavior.

@rjbell4
Copy link

rjbell4 commented Nov 16, 2022

+1 from me, too. I was really hoping to provide a customized warning, but since I cannot get stderr to actually create a newline, I guess I'm stuck with debug.

@jasonk
Copy link

jasonk commented Jan 25, 2023

FWIW, I ended up here because I was trying to do something like this:

. as $line | try fromjson catch $line | stderr

I'm filtering ndjson logs and wanted to be able to use the try fromjson to filter valid json log lines that I could then pipe into further transforms, and wanted to be able to just redirect malformed lines to stderr

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

Successfully merging a pull request may close this issue.

9 participants