From: "Lluís Vilanova" <vilanova@ac.upc.edu>
To: Eric Blake <eblake@redhat.com>
Cc: Stefan Hajnoczi <stefanha@gmail.com>,
Thomas Huth <thuth@redhat.com>,
qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4 5/5] doc: Introduce coding style for errors
Date: Thu, 28 Jan 2016 23:14:42 +0100 [thread overview]
Message-ID: <87bn85tkq5.fsf@fimbulvetr.bsc.es> (raw)
In-Reply-To: <56AA8D2C.5050403@redhat.com> (Eric Blake's message of "Thu, 28 Jan 2016 14:50:36 -0700")
Eric Blake writes:
> On 01/28/2016 02:41 PM, Lluís Vilanova wrote:
>> Gives some general guidelines for reporting errors in QEMU.
>>
>> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
>> ---
>> HACKING | 33 +++++++++++++++++++++++++++++++++
>> 1 file changed, 33 insertions(+)
>>
>> diff --git a/HACKING b/HACKING
>> index 12fbc8a..f5783d4 100644
>> --- a/HACKING
>> +++ b/HACKING
>> @@ -157,3 +157,36 @@ painful. These are:
>> * you may assume that integers are 2s complement representation
>> * you may assume that right shift of a signed integer duplicates
>> the sign bit (ie it is an arithmetic shift, not a logical shift)
>> +
>> +7. Error reporting
>> +
>> +QEMU provides various mechanisms for reporting errors using a uniform format,
>> +ensuring the user will receive them (e.g., shown in QMP when necessary). You
>> +should use one of these mechanisms instead of manually reporting them (i.e., do
>> +not use 'printf()', 'exit()' or 'abort()').
> abort() for unreachable code may be okay, but I'm not sure how to word
> that. Maybe "avoid use 'printf()' or 'exit()', and minimize use of
> 'abort()' situations that should be unreachable code".
Hmmm. I was thinking it'd be more informative to always use error_report_abort()
instead of abort:
* The program name is shown (great for multi-app logs)
* The aborting location is shown (a bit useful to quickly see where it comes
from)
* A message can be provided
I think the message should be optional, since error_report_abort() already
provides more information than plain abort().
But if that seems unreasonable, I can reword it as:
QEMU provides various mechanisms for reporting errors using a uniform format,
ensuring the user will receive them (e.g., shown in QMP when necessary). You
should use one of these mechanisms instead of manually reporting them; i.e.,
do not use 'printf()' nor 'exit()', and minimize the use of 'abort()' to
situations where code should be unreachable and an error message does not make
sense.
> May be worth mentioning that if the user can trigger it (command line,
> hotplug, etc) then we want fatal; if it represents a programming bug
> that the user should not be able to trigger, then abort is okay.
So true. I'll add these.
>> +
>> +7.1. Simple error messages
>> +
>> +The 'error_report*()' functions in "include/qemu/error-report.h" will
>> +immediately report error messages to the user.
>> +
>> +WARNING: Do *not* use 'error_report_fatal()' or 'error_report_abort()' for
>> +errors that are (or can be) triggered by guest code (e.g., some unimplimented
> s/unimplimented/unimplemented/
Fixed in v5 (sorry I forgot about it).
>> +corner case in guest code translation or device code). Otherwise that can be
>> +abused by guest code to terminate QEMU. Instead, you should use
>> +'error_report()'.
>> +
>> +7.2. Errors in user inputs
>> +
>> +The 'loc_*()' functions in "include/qemu/error-report.h" will extend the
>> +messages from 'error_report*()' with references to locations in inputs provided
>> +by the user (e.g., command line arguments or configuration files).
>> +
>> +7.3. More complex error management
>> +
>> +The functions in "include/qapi/error.h" can be used to accumulate error messages
>> +in an 'Error' object, which can be propagated up the call chain where it is
>> +finally reported.
>> +
>> +WARNING: The special 'error_fatal' and 'error_abort' objects follow the same
>> +constrains as the 'error_report_fatal' and 'error_report_abort' functions.
> s/constrains/constraints/
Will add.
Thanks,
Lluis
next prev parent reply other threads:[~2016-01-28 22:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-28 21:41 [Qemu-devel] [RFC][PATCH v4 0/5] utils: Improve and document error reporting Lluís Vilanova
2016-01-28 21:41 ` [Qemu-devel] [PATCH v4 1/5] util: Introduce error reporting functions with fatal/abort Lluís Vilanova
2016-01-28 21:41 ` [Qemu-devel] [PATCH v4 2/5] util: Use new error_report_fatal/abort instead of error_setg(&error_fatal/abort) Lluís Vilanova
2016-01-28 21:41 ` [PATCH v4 3/5] util: [ppc] Use new error_report_fatal() instead of exit() Lluís Vilanova
2016-01-28 21:41 ` [Qemu-devel] " Lluís Vilanova
2016-01-28 21:41 ` [PATCH v4 4/5] util: [ppc] Use new error_report_abort() instead of abort() Lluís Vilanova
2016-01-28 21:41 ` [Qemu-devel] " Lluís Vilanova
2016-01-28 21:45 ` Eric Blake
2016-01-28 21:45 ` [Qemu-devel] " Eric Blake
2016-01-28 22:16 ` Lluís Vilanova
2016-01-28 22:16 ` [Qemu-devel] " Lluís Vilanova
2016-01-28 21:41 ` [Qemu-devel] [PATCH v4 5/5] doc: Introduce coding style for errors Lluís Vilanova
2016-01-28 21:50 ` Eric Blake
2016-01-28 22:14 ` Lluís Vilanova [this message]
2016-01-28 21:55 ` [Qemu-devel] [RFC][PATCH v4 0/5] utils: Improve and document error reporting Lluís Vilanova
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bn85tkq5.fsf@fimbulvetr.bsc.es \
--to=vilanova@ac.upc.edu \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.