From patchwork Wed Feb 3 10:38:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 8200271 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4A1679F37A for ; Wed, 3 Feb 2016 10:38:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 80E1120212 for ; Wed, 3 Feb 2016 10:38:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5324120263 for ; Wed, 3 Feb 2016 10:38:22 +0000 (UTC) Received: from localhost ([::1]:33926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQupJ-0000t8-P9 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 03 Feb 2016 05:38:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQup8-0000ot-Rm for qemu-devel@nongnu.org; Wed, 03 Feb 2016 05:38:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQup7-0000qX-Ej for qemu-devel@nongnu.org; Wed, 03 Feb 2016 05:38:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53678) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQup7-0000qQ-7x for qemu-devel@nongnu.org; Wed, 03 Feb 2016 05:38:09 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id CE6CCC0A848C; Wed, 3 Feb 2016 10:38:08 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-39.ams2.redhat.com [10.36.116.39]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u13Ac6UK009379 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 3 Feb 2016 05:38:07 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1774C303F81B; Wed, 3 Feb 2016 11:38:06 +0100 (CET) From: Markus Armbruster To: Thomas Huth References: <145442963048.1539.13602468921796488810.stgit@localhost> <145442963860.1539.7135815311391731257.stgit@localhost> <87twlraqqw.fsf@blackfin.pond.sub.org> <56B123F7.50505@redhat.com> <20160203050436.GI15080@voom.fritz.box> <87bn7yxgxm.fsf@blackfin.pond.sub.org> <56B1CF5C.7040007@redhat.com> Date: Wed, 03 Feb 2016 11:38:06 +0100 In-Reply-To: <56B1CF5C.7040007@redhat.com> (Thomas Huth's message of "Wed, 3 Feb 2016 10:58:52 +0100") Message-ID: <87io26ulip.fsf@blackfin.pond.sub.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Stefan Hajnoczi , David Gibson , =?utf-8?Q?Llu=C3=ADs?= Vilanova , "Dr . David Alan Gilbert" , qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH v6 1/5] util: Introduce error reporting functions with fatal/abort X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Thomas Huth writes: > On 03.02.2016 10:48, Markus Armbruster wrote: >> David Gibson writes: >> >>> On Tue, Feb 02, 2016 at 10:47:35PM +0100, Thomas Huth wrote: >>>> On 02.02.2016 19:53, Markus Armbruster wrote: >>>>> Lluís Vilanova writes: >>>> ... >>>> >>>>>> diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h >>>>>> index 7ab2355..6c2f142 100644 >>>>>> --- a/include/qemu/error-report.h >>>>>> +++ b/include/qemu/error-report.h >>>>>> @@ -43,4 +43,23 @@ void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); >>>>>> const char *error_get_progname(void); >>>>>> extern bool enable_timestamp_msg; >>>>>> >>>>>> +/* Report message and exit with error */ >>>>>> +void QEMU_NORETURN error_vreport_fatal(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); >>>>>> +void QEMU_NORETURN error_report_fatal(const char *fmt, ...) GCC_FMT_ATTR(1, 2); >>>>> >>>>> This lets people write things like >>>>> >>>>> error_report_fatal("The sky is falling"); >>>>> >>>>> instead of >>>>> >>>>> error_report("The sky is falling"); >>>>> exit(1); >>>>> >>>>> or >>>>> >>>>> fprintf(stderr, "The sky is falling\n"); >>>>> exit(1); >>>>> >>>>> I don't think that's an improvement in clarity. >>>> >>>> The problem is not the existing code, but that in a couple of new >>>> patches, I've now already seen that people are trying to use >>>> >>>> error_setg(&error_fatal, ... ); >>> >>> So, I don't actually see any real advantage to error_report_fatal(...) >>> over error_setg(&error_fatal, ...). >> >> I do. Compare: >> >> (a) error_report(...); >> exit(1); >> >> (b) error_report_fatal(...); >> >> (c) error_setg(&error_fatal, ...); >> >> In my opinion, (a) is clearest: even a relatively clueless reader will >> know what exit(1) does, can guess what error_report() approximately >> does, and doesn't need to know what it does exactly. (b) is slightly >> less obvious, and (c) is positively opaque. >> >> Let's stick to the obvious (a) and be done with it. > > Ok, (a) is fine for me too, as long as we avoid (c). Lluís, could you > maybe add that information to your patch that updates the HACKING text? I feel such detailed advice belings into error.h. Sketch appended. If that doesn't succeed in keeping (c) out, make checkpatch flag it. > (and sorry for the fuzz with error_report_fatal() ... I thought it would > be a good solution to avoid (c), but if (a) is preferred instead, then > we should go with that solution instead). > > And, by the way, what about the spots that currently already use > error_setg(&error_abort, ....) ? Should they be turned into > error_report() + abort() instead? Or only abort(), without error > message, since abort() is only about programming errors? As I wrote in my first reply to this thread, I'd like them to be cleaned up to just abort() or assert(). I like assert(), because it gives me exactly what I can use to debug the programming error: a core dump (if enabled) and a source location (useful when no core dump). I never bought the argument that we should use abort() instead of assert(0) because "what if NDEBUG?!?". If you define NDEBUG, our 600+ abort()s won't save you from our 4000+ assert()s. diff --git a/include/qapi/error.h b/include/qapi/error.h index 45d6c72..ea7e74f 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -162,6 +162,9 @@ ErrorClass error_get_class(const Error *err); * human-readable error message is made from printf-style @fmt, ... * The resulting message should be a single phrase, with no newline or * trailing punctuation. + * Please don't error_setg(&error_fatal, ...), use error_report() and + * exit(), because that's more obvious. + * Likewise, don't error_setg(&error_abort, ...), use assert(). */ #define error_setg(errp, fmt, ...) \ error_setg_internal((errp), __FILE__, __LINE__, __func__, \ @@ -213,6 +216,8 @@ void error_setg_win32_internal(Error **errp, * the error object. * Else, move the error object from @local_err to *@dst_errp. * On return, @local_err is invalid. + * Please don't error_propagate(&error_fatal, ...), use + * error_report_err() and exit(), because that's more obvious. */ void error_propagate(Error **dst_errp, Error *local_err); @@ -291,12 +296,14 @@ void error_set_internal(Error **errp, GCC_FMT_ATTR(6, 7); /* - * Pass to error_setg() & friends to abort() on error. + * Special error destination to abort on error. + * See error_setg() and error_propagate() for details. */ extern Error *error_abort; /* - * Pass to error_setg() & friends to exit(1) on error. + * Special error destination to exit(1) on error. + * See error_setg() and error_propagate() for details. */ extern Error *error_fatal;