All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 05/23] error: Improve documentation around error_append_hint()
Date: Thu, 17 Dec 2015 19:04:37 +0100	[thread overview]
Message-ID: <87wpsduf2i.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <5672E9E5.70004@redhat.com> (Eric Blake's message of "Thu, 17 Dec 2015 09:59:17 -0700")

Eric Blake <eblake@redhat.com> writes:

> On 12/17/2015 09:49 AM, Markus Armbruster wrote:
>> While there, tighten its assertion.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  include/qapi/error.h | 19 +++++++++++++++++--
>>  util/error.c         |  2 +-
>>  2 files changed, 18 insertions(+), 3 deletions(-)
>> 
>> diff --git a/include/qapi/error.h b/include/qapi/error.h
>> index b2362a5..048d947 100644
>> --- a/include/qapi/error.h
>> +++ b/include/qapi/error.h
>> @@ -18,6 +18,15 @@
>>   * Create an error:
>>   *     error_setg(&err, "situation normal, all fouled up");
>>   *
>> + * Create an error and add additional explanation:
>> + *     error_setg(&err, "invalid quark");
>> + *     error_append_hint(&err, "Valid quarks are up, down, strange, "
>> + *                       "charm, top, bottom\n");
>
> Do we want to allow/encourage a trailing dot in the hint?  I'm fine if
> we don't - but once we document its usage, we should probably then be
> consistent with what we document; qemu-option.c used a trailing dot,
> qdev-monitor.c did not.

I'll fix this example.

>> + *
>> + * Do *not* contract this to
>> + *     error_setg(&err, "invalid quark\n"
>> + *                "Valid quarks are up, down, strange, charm, top, bottom");
>> + *
>>   * Report an error to stderr:
>>   *     error_report_err(err);
>>   * This frees the error object.
>> @@ -26,6 +35,7 @@
>>   *     const char *msg = error_get_pretty(err);
>>   *     do with msg what needs to be done...
>>   *     error_free(err);
>> + * Note that this loses hints added with error_append_hint().
>>   *
>>   * Handle an error without reporting it (just for completeness):
>>   *     error_free(err);
>> @@ -128,6 +138,7 @@ ErrorClass error_get_class(const Error *err);
>>   * If @errp is anything else, *@errp must be NULL.
>>   * The new error's class is ERROR_CLASS_GENERIC_ERROR, and its
>>   * human-readable error message is made from printf-style @fmt, ...
>> + * The resulting message should not contain newlines.
>
> Should we also discourage trailing punctuation?

Yes.  How to best phrase it?

> Should we also mention no need for leading 'error: ' prefix?

Unlike the other anti-patterns, this one doesn't seem frequent in new
code.

>>   */
>>  #define error_setg(errp, fmt, ...)                              \
>>      error_setg_internal((errp), __FILE__, __LINE__, __func__,   \
>> @@ -184,7 +195,11 @@ void error_propagate(Error **dst_errp, Error *local_err);
>>  
>>  /**
>>   * Append a printf-style human-readable explanation to an existing error.
>> - * May be called multiple times, and safe if @errp is NULL.
>> + * @errp may be NULL, but neither &error_fatal nor &error_abort.
>
> As a native speaker, 'not' sounds better than 'neither' in that
> sentence.  But I think both choices are grammatically correct.

You mean "not &error_abort or &error_abort"?

>> + * Trivially the case if you call it only after error_setg() or
>> + * error_propagate().
>> + * May be called multiple times.  The resulting hint should end with a
>> + * newline.
>>   */
>>  void error_append_hint(Error **errp, const char *fmt, ...)
>>      GCC_FMT_ATTR(2, 3);
>> @@ -218,7 +233,7 @@ void error_free_or_abort(Error **errp);
>>  /*
>>   * Convenience function to error_report() and free @err.
>>   */
>> -void error_report_err(Error *);
>> +void error_report_err(Error *err);
>>  
>>  /*
>>   * Just like error_setg(), except you get to specify the error class.
>> diff --git a/util/error.c b/util/error.c
>> index 9b27c45..ebfb74b 100644
>> --- a/util/error.c
>> +++ b/util/error.c
>> @@ -132,7 +132,7 @@ void error_append_hint(Error **errp, const char *fmt, ...)
>>          return;
>>      }
>>      err = *errp;
>> -    assert(err && errp != &error_abort);
>> +    assert(err && errp != &error_abort && errp != &error_fatal);
>
> Otherwise looks reasonable.
>
>>  
>>      if (!err->hint) {
>>          err->hint = g_string_new(NULL);
>> 

Thanks!

  reply	other threads:[~2015-12-17 18:04 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-17 16:49 [Qemu-devel] [PATCH v2 00/23] Error reporting cleanups and fixes Markus Armbruster
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 01/23] qemu-nbd: Replace BSDism <err.h> by error_report() Markus Armbruster
2015-12-17 17:17   ` Eric Blake
2015-12-17 18:52     ` Markus Armbruster
2015-12-17 19:56       ` Eric Blake
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 02/23] error: Use error_report_err() where appropriate (again) Markus Armbruster
2015-12-17 17:33   ` Eric Blake
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 03/23] error: Use error_report_err() instead of monitor_printf() Markus Armbruster
2015-12-17 18:06   ` Eric Blake
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 04/23] error: Use error_report_err() instead of ad hoc prints Markus Armbruster
2015-12-17 20:10   ` Eric Blake
2015-12-18  8:49     ` Markus Armbruster
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 05/23] error: Improve documentation around error_append_hint() Markus Armbruster
2015-12-17 16:59   ` Eric Blake
2015-12-17 18:04     ` Markus Armbruster [this message]
2015-12-17 18:16       ` Eric Blake
2015-12-17 19:00         ` Markus Armbruster
2015-12-17 19:53           ` Eric Blake
2015-12-18  9:11             ` Markus Armbruster
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 06/23] block: Clean up "Could not create temporary overlay" error message Markus Armbruster
2015-12-17 20:16   ` Eric Blake
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 07/23] qemu-nbd: Clean up "Failed to load snapshot" " Markus Armbruster
2015-12-17 20:17   ` Eric Blake
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 08/23] test-throttle: Simplify qemu_init_main_loop() error handling Markus Armbruster
2015-12-17 20:19   ` Eric Blake
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 09/23] error: New error_prepend(), error_reportf_err() Markus Armbruster
2015-12-17 20:23   ` Eric Blake
2015-12-18  9:13     ` Markus Armbruster
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 10/23] error: Don't decorate original error message when adding to it Markus Armbruster
2015-12-17 20:32   ` Eric Blake
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 11/23] error: Use error_reportf_err() where it makes obvious sense Markus Armbruster
2015-12-17 20:39   ` Eric Blake
2015-12-18  9:18     ` Markus Armbruster
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 12/23] error: Use error_prepend() " Markus Armbruster
2015-12-17 20:43   ` Eric Blake
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 13/23] spapr: Use error_reportf_err() Markus Armbruster
2015-12-17 20:44   ` Eric Blake
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 14/23] migration: Use error_reportf_err() instead of monitor_printf() Markus Armbruster
2015-12-17 20:46   ` Eric Blake
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 15/23] qemu-io qemu-nbd: Use error_report() etc. instead of fprintf() Markus Armbruster
2015-12-17 20:51   ` Eric Blake
2015-12-17 20:57     ` Eric Blake
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 16/23] error: Strip trailing '\n' from error string arguments (again) Markus Armbruster
2015-12-17 20:57   ` Eric Blake
2015-12-18  9:47     ` Markus Armbruster
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 17/23] vmdk: Clean up control flow in vmdk_parse_extents() a bit Markus Armbruster
2015-12-17 21:00   ` Eric Blake
2015-12-18  9:54     ` Markus Armbruster
2015-12-18  0:48   ` Fam Zheng
2015-12-17 16:49 ` [Qemu-devel] [PATCH v2 18/23] vmdk: Clean up "Invalid extent lines" error message Markus Armbruster
2015-12-17 21:09   ` Eric Blake
2015-12-18  0:52   ` Fam Zheng
2015-12-18  9:56     ` Markus Armbruster
2015-12-17 16:50 ` [Qemu-devel] [PATCH v2 19/23] pci-assign: Clean up "Failed to assign" error messages Markus Armbruster
2015-12-17 21:45   ` Eric Blake
2015-12-17 16:50 ` [Qemu-devel] [PATCH v2 20/23] vhdx: Fix "log that needs to be replayed" error message Markus Armbruster
2015-12-17 21:52   ` Eric Blake
2015-12-17 16:50 ` [Qemu-devel] [PATCH v2 21/23] error: Clean up errors with embedded newlines (again) Markus Armbruster
2015-12-17 21:53   ` Eric Blake
2015-12-18 10:04     ` Markus Armbruster
2015-12-17 16:50 ` [Qemu-devel] [PATCH v2 22/23] hw/s390x: Rename local variables Error *l_err to just err Markus Armbruster
2015-12-17 21:54   ` Eric Blake
2015-12-17 16:50 ` [Qemu-devel] [PATCH v2 23/23] s390/sclp: Simplify control flow in sclp_realize() Markus Armbruster
2015-12-17 17:25   ` Cornelia Huck
2015-12-17 21:54   ` Eric Blake
2015-12-17 17:26 ` [Qemu-devel] [PATCH v2 00/23] Error reporting cleanups and fixes Cornelia Huck

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=87wpsduf2i.fsf@blackfin.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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.