qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Abuse of warnings for unhandled errors and programming errors
@ 2025-08-08  9:30 Markus Armbruster
  2025-08-19 12:30 ` Daniel P. Berrangé
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Armbruster @ 2025-08-08  9:30 UTC (permalink / raw)
  To: qemu-devel

In "[PATCH 00/12] Error reporting cleanup, a fix, and &error_warn
removal", I challenged the use of warnings in a few places.  I think the
topic deserves a wider audience than the one a rather pedestrian cleanup
series draws.


To make my case, I need to start with errors.  We distinguish between
ordinary errors (for lack of a better word) and programming errors.

Ordinary errors are things like nonsensical user requests, unavailable
resources, and so forth.  A correct program is prepared for such
failures, detects them, and reports them to the user.  The user can then
fix their request, try again when resources are available, and so forth.

Tools for reporting ordinary errors are error_report(),
error_report_err(), &error_fatal, and friends.

Programming errors are bugs.  A developer needs to fix the program.
Unlike ordinary errors, programming errors are *unexpected*.

Programming errors are commonly not recoverable.  The proper tool for
unrecoverable ones is assertions.  &error_abort can be a convenient way
to assert "this can't fail".


On to warnings.

When some failure doesn't prevent satisfying some request, an ordinary
error can be misleading.  We make it a warning instead then.

What if it's a programming error we recover from?

Aside: trying to recover in a buggy program is risky, but that's not the
debate I want to have here.

How do we want such recoverable programming errors reported?

Warning?  We seem to be abusing warnings this way, and I hate it.  What
we have to report is a *bug*, and we should make that crystal clear.
"warning: FunctionYouNeverHeardAbout() failed" does not.  It could be
anything, and you likely need to look at the source to find out.

Ordinary error reporting with "internal error: " prefix, so the user
understands this is a bug, and all they can do about it is report it?

Log the bug somehow?

Thoughts?


Regardless of all that, beware of "this shouldn't fail, and if it does,
I don't know how to handle it / can't be bothered to handle it, so I
just spit out a warning and hope for the best."  Stop and *think*
whether it is a programming error or an ordinary error that is difficult
/ inconvenient / impossible to handle.  Then do the right thing if
practical.  If not, you're accepting a defect.  Make it locally obvious
that it's a defect, so it's at least a *known* defect, and the next guy
coming along won't have to guess.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-09-16 13:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-08  9:30 Abuse of warnings for unhandled errors and programming errors Markus Armbruster
2025-08-19 12:30 ` Daniel P. Berrangé
2025-09-10 11:05   ` Markus Armbruster
2025-09-15 18:02     ` Daniel P. Berrangé
2025-09-16 13:25       ` Markus Armbruster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).