Received: from eggs.gnu.org ([2001:4830:134:3::10]:53445) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0vEG-0005lQ-Jn for qemu-devel@nongnu.org; Mon, 23 Nov 2015 12:48:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a0vED-0001ap-QS for qemu-devel@nongnu.org; Mon, 23 Nov 2015 12:48:40 -0500 Received: from roura.ac.upc.edu ([147.83.33.10]:52826 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0vED-0001Zx-Gr for qemu-devel@nongnu.org; Mon, 23 Nov 2015 12:48:37 -0500 From: =?utf-8?Q?Llu=C3=ADs_Vilanova?= References: <144828831182.22449.10763712892565113940.stgit@localhost> <56534371.3000604@redhat.com> Date: Mon, 23 Nov 2015 18:48:34 +0100 In-Reply-To: <56534371.3000604@redhat.com> (Eric Blake's message of "Mon, 23 Nov 2015 09:48:49 -0700") Message-ID: <877fl8k3nx.fsf@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] [doc] Introduce coding style for errors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Stefan Hajnoczi , Thomas Huth , qemu-devel@nongnu.org, Markus Armbruster , "Dr . David Alan Gilbert" Eric Blake writes: > On 11/23/2015 07:18 AM, Llu=C3=ADs Vilanova wrote: >> Gives some general guidelines for reporting errors in QEMU. > This is more than just a doc patch; you are actually proposing new code > in the way of &error_now. The commit message must absolutely mention > changes like this, or possibly even split this into two changes > (document existing behavior, then add new code and its matching docs). Yes, sorry. I added it after writing most of the text, and forgot to update= the patch description. Will resend a fixed version. [...] >> +++ b/HACKING >> @@ -157,3 +157,55 @@ 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 two different mechanisms for reporting errors. You should= use one >> +of these mechanisms instead of manually reporting them (i.e., do not use >> +'printf', 'exit' or 'abort'). > There are places where calling exit() is okay (when parsing command-line > arguments), and where abort() is okay (in code that cannot be reached, > such as a dead switch() branch). So I don't know if this sentence > should be reworded, or if adding even something as simple as "generally" > will weaken it too much. Wouldn't it be better to use "error_setg(&error_fatal, ...)" instead of an = exit? Same applies to 'abort' and 'error_abort'; it additionally provides a messa= ge plus a bit of of information on the failed function/file/line. [...] >> + >> +For convenience, you can also use 'error_setg_errno' and 'error_setg_wi= n32' to >> +append a message for OS-specific errors, and 'error_setg_file_open' for= errors >> +when opening files. > I'm worried that we may be trying to duplicate too much information, in > which case one will get out of sync. Merely pointing to error.h may be > good enough for the purposes of HACKING, rather than calling out all the > subtleties (leaving that for error.h). Aha. I can simply reference the three special error objects, and leave the = rest to error.h. >>=20 >> +/* >> + * Pass to error_setg() & friends to immediately show an error. >> + * >> + * Has the same formatting of #error_abort, but does not terminate QEMU. > Doesn't that make it useful only for warnings? If so, should it > automatically prepend "warning: "? Where do you propose using it, for a > demonstration of why it is useful? Actually, this new object caters to some comments I received, where guest a= nd device code should never terminate QEMU. To me it sounds like a non-termina= ting abort, but I can certainly rename to object to 'errror_warn' and prepend the appropriate "warning: " text. >> +++ b/util/error.c >> @@ -27,6 +27,7 @@ struct Error >>=20 >> Error *error_abort; >> Error *error_fatal; >> +Error *error_now; >>=20 >> static void error_handle_fatal(Error **errp, Error *err) >> { >> @@ -62,9 +63,14 @@ static void error_setv(Error **errp, err-> func =3D func; >>=20 >> error_handle_fatal(errp, err); >> - *errp =3D err; >> - >> - errno =3D saved_errno; >> + if (errp =3D=3D &error_now) { >> + fprintf(stderr, "Unexpected error in %s() at %s:%d:\n", >> + err->func, err->src, err->line); >> + error_report_err(err); > This lacks timestamping information on the "Unexpected error..." output; > is that going to be a problem? The code mimics 'error_handle_fatal', which does not show any timestamp. Thanks, Lluis --=20 "And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth