|
|
|
|
|
by kazinator
1570 days ago
|
|
> There's our "No space" error getting reported by the OS, but no matter, the program silently swallows it and returns 0, the code for success. That's a bug! Bzzt, no. You can't say that without knowing what the program's requirements are. Blindly "fixing" a program to indicate failure due to not being able to write to standard output could break something. Maybe the output is just a diagnostic that's not important, but some other program will reacts to the failed status, causing an issue. Also, if a program produces output with a well-defined syntax, then the termination status may be superfluous; the truncation of the output can be detected by virtue of that syntax being incomplete. E.g. JSON hello world fragment: puts("{\"hello\":\"world\"}");
return 0;
if something is picking up the output and parsing it as JSON, it can deduce from a failed parse that the program didn't complete, rather than going by termination status. |
|
This is bad advice. Consider output that might be truncated but can't be detected (mentioned in the article).
The exit status is the only reliable way to detect failures (unless you have a separate communication channel and send a final success message).