Make more of share/functions print error messages to stderr #8855
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Hi. I was using
some_fish_func > some_file.something
and had a bug in my program (where I misusedpushd
in some irrelevant way). This caused me to notice thatpushd
logged its error message to stdout and not stderr, since it sort of1 corrupted the file.My personal feelings here is that it is typically Bad Form for programs to use stdout for writing messages intended for the user, especially error messages (with some exceptions of course).
I have fish-shell checked out from prior patches so I took a peek. I noticed that most functions do the "right thing" and log their complaints to stderr, which I interpreted to mean that probably a patch fixing
pushd
would probably be appreciated. Unfortunately, at this point my "What If I Fixed It All" brain kicked in, so I started looking to see if there's anything else that this applies to, and there is.That dream was pretty short-lived though, since fixing each part requires figuring out if it's program output vs an error... and I really don't want to break anything in this patch. So I ended up just doing the obvious bits.
... And after a while of doing with that, I decided that I really don't have time to shave this yak, especially given that I'm probably missing a lot of places anyway. Really, someone who knows the code better is probably the person who should finish that task (or not2).
So this is just a start on the problem, and only addresses a small handful of cases. I don't think it makes anything worse though, so at least there's that.
Anyway, of the changes in this patch, I think the directory manipulation stuff and
seq
are the most important. It's likely that those are used often enough in scripts for their stdout to frequently be captured as a string, which would just result in bad behavior.I think the cases which are least important are ones that are almost certainly only used interactively. For some reason, I still touched a few of these. That said, I'm (of course) willing to revert any of these changes if you'd prefer.
TODOs:
Changes to fish usage are reflected in user documentation/manpages.
No changes.
Tests have been added for regressions fixed
Adding tests for this would be a nightmare. Please do not ask this of me.
User-visible changes noted in CHANGELOG.rst
I think this is technically user visible, but in practice most of the users who notice will just be finding new bugs in their code.
I guess maybe some code attempts to parse one of these error messages from stdout, but such code is very fragile anyway.
P.S. While I'm here, since it's technically related... I think it would be good for fish to have
printf
/echo
variants3 that automatically use stderr. (TBH I mostly want this as a user, because the redirect syntax is weird and hard for me to remember I have to look it up every time). That said, if you used it consistently, it would make auditing stuff like this in the future easier... at least after you switched to use it (it seems unlikely to make it any easier to do the first time).Footnotes
Well, the file would be corrupted anyway because of the bug, this just made it happen slightly sooner. ↩
I won't judge if nothing happens after this PR. I get it -- it's very hard in open source to find the resources for projects like "ensure all the sites where we $frobnicate are Good And Proper", especially if it only gets hit in failure modes.
For stuff like this it is especially hard, since it seems somewhat resistant to automation -- any tooling would have to figure out what is an error message vs what is the real output. (But maybe there are some heuristics which would work enough of the time to be useful here) ↩
For example, they could be
eprintf
and... uh...eecho
?...errcho
? ... Uh, coming up with a name better than those is left as an exercise for the reader. ↩