Please, use stderr and stdout properly!

Programming applications for making music on Linux.

Moderators: MattKingUSA, khz

Post Reply
grammo
Established Member
Posts: 45
Joined: Thu Mar 18, 2021 1:19 pm
Has thanked: 1 time
Been thanked: 5 times

Please, use stderr and stdout properly!

Post by grammo »

Lot's of linuxaudio devs seems to do this wrong: sending error messages to stdout instead of stderr and non error messages to stderr instead of stdout.

Read about file descriptors here:
https://mywiki.wooledge.org/BashGuide/InputAndOutput

tavasti
Established Member
Posts: 2047
Joined: Tue Feb 16, 2016 6:56 am
Location: Kangasala, Finland
Has thanked: 369 times
Been thanked: 208 times
Contact:

Re: Please, use stderr and stdout properly!

Post by tavasti »

One really annoying thing is that when giving argument --help you get that help message on stderr. If it is longer than one screen and want to pipe it to less, need redirection.

Linux veteran & Novice musician

Latest track: https://www.youtube.com/watch?v=ycVrgGtrBmM

j_e_f_f_g
Established Member
Posts: 2032
Joined: Fri Aug 10, 2012 10:48 pm
Been thanked: 357 times

Re: Please, use stderr and stdout properly!

Post by j_e_f_f_g »

Indeed, lots of programmers get this wrong. A gui app should never print anything to stdout nor stderr. An error message should be presented in a pop-up dialog, so the enduser doesn't miss it. And it should be an informative error message that can help the enduser solve the problem -- not something cryptic like "myCPlusObj::SomeFunction error 00057327".

Non-error messages should be used to indicate progress, such as informing the user what the program is currently busy doing, so that the user can know why the program isn't responding to his input. And they should scroll into and out of view without any action required by the enduser.

And I wish programmers wouldn't make release versions that print tons of debugging messages to stdout. Leave that to the debug versions.

Author of BackupBand at https://sourceforge.net/projects/backupband/files/
My fans show their support by mentioning my name in their signature.

tavasti
Established Member
Posts: 2047
Joined: Tue Feb 16, 2016 6:56 am
Location: Kangasala, Finland
Has thanked: 369 times
Been thanked: 208 times
Contact:

Re: Please, use stderr and stdout properly!

Post by tavasti »

j_e_f_f_g wrote: Fri Jan 27, 2023 7:00 am

Indeed, lots of programmers get this wrong. A gui app should never print anything to stdout nor stderr. An error message should be presented in a pop-up dialog, so the enduser doesn't miss it. And it should be an informative error message that can help the enduser solve the problem -- not something cryptic like "myCPlusObj::SomeFunction error 00057327".

For that 'never' part I would change a bit:

  • if there is problem that prevents opening GUI, then there should be error message in stderr
  • if user gives command-line option verbose/debug, then there should be messages in stderr, telling what is happening.
j_e_f_f_g wrote: Fri Jan 27, 2023 7:00 am

And I wish programmers wouldn't make release versions that print tons of debugging messages to stdout. Leave that to the debug versions.

Debug stuff should not be compile time option, but command line or config file option. There is few less annoying things than situation where non-debug version does not work and debug version works.
But on rest, fully agree with you.

Linux veteran & Novice musician

Latest track: https://www.youtube.com/watch?v=ycVrgGtrBmM

grammo
Established Member
Posts: 45
Joined: Thu Mar 18, 2021 1:19 pm
Has thanked: 1 time
Been thanked: 5 times

Re: Please, use stderr and stdout properly!

Post by grammo »

Clicking dialog buttons is good fun indeed @j_e_f_f_g

Silence is golden.

And if a GUI app prints messages (lot's of apps do it and and I don't see a reason why they shouldn't), it should send errors to stderr.

With Bash this is mentioned right at the moment you want to learn it. Python does or can do it for you it seems, a good way to keep people happy and ignorant I guess.

But yeah, it's now hard to split logging messages from modular applications in a modular setup as with nsmd. Quite easy to fix on the other hand.

j_e_f_f_g
Established Member
Posts: 2032
Joined: Fri Aug 10, 2012 10:48 pm
Been thanked: 357 times

Re: Please, use stderr and stdout properly!

Post by j_e_f_f_g »

grammo wrote:

I don't see a reason why <a GUI app> shouldn't send errors to stderr.

Because, unless the user starts a gui app from a terminal window (and why would he?), he'll never see those errors.

stdin, stderr, and stdout are idioms best confined to non-gui apps. Developers should design an app to work within the context in which it's run. If an app is likely to be launched by a desktop icon, design your error reporting to be done graphically, with user interaction/feedback.

Author of BackupBand at https://sourceforge.net/projects/backupband/files/
My fans show their support by mentioning my name in their signature.

folderol
Established Member
Posts: 2069
Joined: Mon Sep 28, 2015 8:06 pm
Location: Here, of course!
Has thanked: 224 times
Been thanked: 400 times
Contact:

Re: Please, use stderr and stdout properly!

Post by folderol »

I know people who start a GUI application from the command line, and are very grateful when they come across a program that supports this.

Also, in the case of Yoshimi you have a choice: GUI only, CLI only, Both!
We have users in all three categories.
We also properly separate errors from normal messages. System/Program errors always go to the CLI. Normal messages can be directed to either the CLI or to a GUI console window.

The Yoshimi guy {apparently now an 'elderly'}
j_e_f_f_g
Established Member
Posts: 2032
Joined: Fri Aug 10, 2012 10:48 pm
Been thanked: 357 times

Re: Please, use stderr and stdout properly!

Post by j_e_f_f_g »

I think people are grateful that gui apps display error messages to a console, because few OSS developers put any effort into making the app's gui error reporting as comprehensive. The vast majority of the time that I do a code audit, and notice lots of printf()'s and writes to stderr, I find that there is scant little use (if any) of dialog boxes to report meaning error messages.

And not coincidentally, functions fail to return error codes, nor have well-designed error handling. It seems most devs always assume every function they write will never fail. So there's no error handling designed in. Then later when the dev gets enduser feedback that his code is failing, instead of adding proper error handling, the lazy dev typically inserts a printf statement, followed by an exit(). That makes trouble-shooting so much more difficult than it needs to be, and forces even a gui app's trouble-shooting to be confined to a terminal.

Developers just find it too easy to just dump tons of text to a console window. So they give the enduser little choice in trouble-shooting. Even if it's a gui app, the enduser is expected to run it from a terminal and submit that heap of console text when trouble-shooting.

Author of BackupBand at https://sourceforge.net/projects/backupband/files/
My fans show their support by mentioning my name in their signature.

User avatar
sadko4u
Established Member
Posts: 986
Joined: Mon Sep 28, 2015 9:03 pm
Has thanked: 2 times
Been thanked: 359 times

Re: Please, use stderr and stdout properly!

Post by sadko4u »

That's all because we're missing the stdlog file descriptor.

LSP (Linux Studio Plugins) Developer and Maintainer.
grammo
Established Member
Posts: 45
Joined: Thu Mar 18, 2021 1:19 pm
Has thanked: 1 time
Been thanked: 5 times

Re: Please, use stderr and stdout properly!

Post by grammo »

grammo wrote: Fri Jan 27, 2023 10:06 am

But yeah, it's now hard to split logging messages from modular applications in a modular setup as with nsmd. Quite easy to fix on the other hand.

The NSM api has also a messages system:

"1.2.4.4. Status Messages

/nsm/client/message i:priority s:message

Clients may send miscellaneous status updates to the server for possible display to the user. This may simply be chatter that is normally written to the console. priority should be a number from 0 to 3, 3 being the most important.

Clients which have this capability should include :message: in their announce capability string. "

So if those modular apps / NSM clients sends errors to stderr and NSM related messages to the server, it should give you the possibility to generate a much cleaner log I would think.

Anyway, the Unix spirit seems to be left on Linux. MS Windows apps on a system formerly known as Unix, or am I too pessimistic now? :) Maybe that designer spirit is even more a live at OSX, but, as a Linux user I can't tell. :wink:

I found this fun to read: http://www.catb.org/~esr/writings/taoup/html/
As well as the Unix Haters Handbook of course!

grammo
Established Member
Posts: 45
Joined: Thu Mar 18, 2021 1:19 pm
Has thanked: 1 time
Been thanked: 5 times

Re: Please, use stderr and stdout properly!

Post by grammo »

Ah that line is in nsm.h, that's why all NSM clients print this to stderr

https://github.com/jackaudio/new-sessio ... nsm.h#L538

Post Reply