-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
echo may silently fail to write to stdout #16366
Comments
The most sensible is to raise an exception, swallowing errors always creates more problems than it solves and as you mentioned leads to difficult debugging because cause and effect can be spread far apart. can you write a PR to fix this by raising an refs timotheecour#380 somewhat related |
fixed by #16367, feel free to re-open if you disagree |
echo
may fail to write to stdout. When it does, it causesstdout
to be put into an error state (such thatc_ferror(stdout)
is non-zero) but does not raise any exception. Then a future, possibly far-distant attempt tostdout.write
will fail with an exception. Having the error reported so far from when the failure happened is difficult to debug.Example
I'm having trouble duplicating the setup that caused this (it involves spawning several subprocesses, some of which set stdout to nonblocking). I was seeing errno 35, resource busy.
Hopefully you can see that errors are ignored by looking at the code for echo. Lines 801, 803 and 804 are where failed writes might happen (note the
discard
on each line).Nim/lib/system/io.nim
Lines 797 to 804 in d15f63a
Suppose the following happens:
c_fwrite(...)
fails to write.errno = 35
c_ferror(stdout) == 1
c_ferror
is not checked withinecho
errno
to be set to something else. In my case it waserrno = 2
.stdout.write(...)
is attemptedstdout.write
checksc_ferror(stdout)
, it will see there's a problem and report the error using the now-invaliderrno == 2
.Possible solutions
I don't know what the solution is. I can understand why it's desirable to have
echo
rarely raise exceptions, especially as a debugging tool. I'm just now hesitant to useecho
for anything but debugging.echo
raise an exception ifc_fwrite
failsecho
write a warning to stderr ifc_fwrite
fails (but don't raise an exception)echo
docs, indicating that failures are swallowedecho
(maybeEcho
?) if it's desirable to keepecho
the way it isAdditional Information
The reason my
echo
was failing is specific to macOS, but I believe this issue applies to any POSIX system.The text was updated successfully, but these errors were encountered: