[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#927992: Write errors and warnings to STDERR, don't hide them if not a tty



Package: apt
Version: 1.8.0
File: /usr/bin/apt-cache

In Unix/Linux we have STDOUT and STDERR. Please just use these two,
and don't invent "smarter ways."

Really really bad and this will come back to bite you one day:

You have a kind of message that is only shown if the user is on a tty.

You don't user the industry standard of sending it to STDERR,
You instead just hide it... if the user apparently isn't using a TTY.

One can't even pipe the output of your program to any other program,
expecting messages to go to STDERR. The message just disappears!

$ apt-cache show twitter-bootstrap
N: Can't select candidate version from package twitter-bootstrap as it has no candidate
N: Can't select versions from package 'twitter-bootstrap' as it is purely virtual
N: No packages found
$ apt-cache show twitter-bootstrap 2>&1|wc
      0       0       0

In fact I can think of no other program in the entire history of Unix
that has decided to do that.

If the user doesn't want the message he can just do 2> /dev/null. Or
2>&- . That's how we do things on Linux/Unix.

$ apt show twitter-bootstrap
Package: twitter-bootstrap
State: not a real package (virtual)
N: Can't select candidate version from package twitter-bootstrap as it has no candidate
N: Can't select versions from package 'twitter-bootstrap' as it is purely virtual
N: No packages found

Now experimenting with apt,

$ apt show twitter-bootstrap 2>&1 | nl -b a
     1
     2  WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
     3
     4  Package: twitter-bootstrap
     5  State: not a real package (virtual)
$ apt show twitter-bootstrap | nl -b a

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

     1  Package: twitter-bootstrap
     2  State: not a real package (virtual)

Aptitude is much more consistent,

$ aptitude show twitter-bootstrap | nl -b a
     1  Package: twitter-bootstrap
     2  State: not a real package
     3  Provided by: libjs-twitter-bootstrap (2.0.2+dfsg-10)
$ aptitude show twitter-bootstrap
Package: twitter-bootstrap
State: not a real package
Provided by: libjs-twitter-bootstrap (2.0.2+dfsg-10)

Anyway your idea of a tty is fine for you. But not for how many users
will use these programs. Thanks.


Reply to: