From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQdb0-0002hx-S2 for qemu-devel@nongnu.org; Tue, 02 Feb 2016 11:14:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQdaz-0005ZR-7L for qemu-devel@nongnu.org; Tue, 02 Feb 2016 11:14:26 -0500 Received: from roura.ac.upc.edu ([147.83.33.10]:58670 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQday-0005ZD-RX for qemu-devel@nongnu.org; Tue, 02 Feb 2016 11:14:25 -0500 From: =?utf-8?b?TGx1w61z?= Vilanova Date: Tue, 2 Feb 2016 17:14:21 +0100 Message-Id: <145442966104.1539.5045217656318286174.stgit@localhost> In-Reply-To: <145442963048.1539.13602468921796488810.stgit@localhost> References: <145442963048.1539.13602468921796488810.stgit@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v6 5/5] doc: Introduce coding style for errors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Thomas Huth , Stefan Hajnoczi , "Dr . David Alan Gilbert" , Markus Armbruster , David Gibson Gives some general guidelines for reporting errors in QEMU. Signed-off-by: Llu=C3=ADs Vilanova --- HACKING | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/HACKING b/HACKING index 12fbc8a..b738bce 100644 --- a/HACKING +++ b/HACKING @@ -157,3 +157,40 @@ 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 fo= rmat, +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()'). + +As a general rule, use the 'fatal' forms below for errors that can be tr= iggered +by the user (e.g., commandline, hotplug, etc.), and the 'abort' forms fo= r +programming errors that the user should not be able to trigger. + +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()' f= or +errors that are (or can be) triggered by guest code (e.g., some unimplem= ented +corner case in guest code translation or device code). Otherwise, that c= an 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 p= rovided +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 +constraints as the 'error_report_fatal()' and 'error_report_abort()' fun= ctions.