[smartmontools-support] Discuss: smartctl --json: should output messages to stderr on fail

Christian Franke Christian.Franke at t-online.de
Mon Jan 30 14:24:19 CET 2023


Hi Eike,

Eike Dierks wrote:
> Hi at the smartmon team
>
> I'd like to suggest a change to the current behaviour of
>    smartctl --json
> regarding how to show errors on stderr
>
> When I execute:
>    smartctl --json nosuchdevice
> no error messages show up on stderr.
>
> All the errors are perfectly described in the json[messages] on stdout.
> But there is nothing on stderr.
>
> I'd like to suggest to change that behaviour.
> If a command goes wrong, it should write the problems to stderr.
> The reporting of problems should not be suppressed.
> This is why stderr was invented for.
>
> Let me give a use case:
> - display the temparature of a disk
> - build a wrapper script to extract the value from the json output
> - show the errors on fail
>
> At the current state,
> I have to parse the json for the error messages
> just to write them to stderr, myself.
>
> I'd like t suggest:
> that any errors are always output to stderr,
> even, when smartctl is invoked with --json

This makes sense in your use case, but changing such long standing 
default behavior may break existing ones. This would in particular be 
the case if someone accidentally used 'smartctl -j ... 2>&1'.

I would suggest to add a new option to enable this behavior. It could 
also be useful for plaintext output. For example:

-e, --errors-to[=out+err]: Write warnings and error messages also to 
stderr. This output is always in plaintext format, even if JSON output 
is selected.
--errors-to=err: Write warnings and error messages only to stderr. If 
JSON output is selected, this has the same effect as '-e'.

Thanks,
Christian



More information about the Smartmontools-support mailing list