qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Peter Crosthwaite <crosthwaitepeter@gmail.com>, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, armbru@redhat.com
Subject: Re: [Qemu-devel] [RFC PATCH v1 05/25] error: Add error prefix API
Date: Fri, 11 Sep 2015 10:04:34 -0600	[thread overview]
Message-ID: <55F2FB92.6020608@redhat.com> (raw)
In-Reply-To: <1f763d85b66d3767b96afaa59d483005bb3951e5.1441667360.git.crosthwaite.peter@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3458 bytes --]

On 09/10/2015 11:33 PM, Peter Crosthwaite wrote:
> Add an API to prefix an already set error with a caller-centric
> message.
> 
> If multiple errors are set, all are prefixed individually.
> 

Might be nice to rebase your series to add this first, prior to
multi-error support.  (That is, while prefixing multiple errors requires
multi-error support, adding caller-centric prefix might be useful even
now without multi-error).

> Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
> ---
> 
>  include/qapi/error.h |  6 ++++++
>  util/error.c         | 26 ++++++++++++++++++++++++++
>  2 files changed, 32 insertions(+)
> 
> diff --git a/include/qapi/error.h b/include/qapi/error.h
> index f44c451..b25c72f 100644
> --- a/include/qapi/error.h
> +++ b/include/qapi/error.h
> @@ -78,6 +78,12 @@ ErrorClass error_get_class(const Error *err);
>  Error *error_copy(const Error *err);
>  
>  /**
> + * Prefix an error message with a formatted string.
> + */
> +
> +void error_prefix(Error *err, const char *fmt, ...);

The string is basically only adding details for human consumption.

> +++ b/util/error.c
> @@ -19,6 +19,7 @@ struct Error
>      char *msg;
>      ErrorClass err_class;
>      struct Error *next;
> +    bool prefixed;
>  };

I'm not sure I follow why this field is needed.

>  
>  Error *error_abort;
> @@ -142,6 +143,26 @@ const char *error_get_pretty(Error *err)
>      return err->msg;
>  }
>  
> +void error_prefix(Error *err, const char *fmt, ...) {

Brace on its own line.

> +    char *msg;
> +    char *fmt_full;
> +    va_list ap;
> +
> +    if (!err || err->prefixed) {
> +        return;
> +    }
> +    err->prefixed = true;
> +
> +    msg = err->msg;
> +    fmt_full =  g_strdup_printf("%s%%s", fmt);
> +
> +    va_start(ap, fmt);
> +    err->msg = g_strdup_printf(fmt_full, ap, msg);

I don't think that is portable.  Passing va_list as an argument to plain
printf just isn't going to do what you think.
(There has been a request to add recursive printf via %r,
http://austingroupbugs.net/view.php?id=800, but glibc does not support
the extension yet)

It's not to say that you can't chain, just that you can't chain like
this.  I don't know if using GString internally to error would make the
matter any easier (but one of the patches that will probably land before
yours, and thus affect your need to rebase, is mine which adds use of
GString for adding a human-readable SUFFIX rather than prefix:
https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg02818.html)

> +    va_end(ap);
> +    g_free(fmt_full);
> +    g_free(msg);
> +}
> +
>  void error_report_err(Error *err)
>  {
>      error_report("%s", error_get_pretty(err));
> @@ -170,6 +191,11 @@ void error_propagate(Error **dst_errp, Error *local_err)
>  
>          *dst_errp = local_err;
>          for (i = local_err; i; i = i->next) {
> +            /* Propagation implies that the caller is no longer the owner of the
> +             * error. Therefore reset prefixes, so higher level handlers can
> +             * prefix again.
> +             */
> +            i->prefixed = false;

I'm still not quite sure I buy the semantics of this flag.

>              dst_errp = &i->next;
>          }
>          *dst_errp = old_dst_err;
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2015-09-11 16:04 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-11  5:33 [Qemu-devel] [RFC PATCH v1 00/25] error: Automatic error concatenation and prefixing Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 01/25] exec: convert error_report to error_report_err Peter Crosthwaite
2015-09-11 15:28   ` Eric Blake
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 02/25] s390x: virtio-ccw: Remove un-needed if guard Peter Crosthwaite
2015-09-11 15:28   ` Eric Blake
2015-09-14  7:09   ` Cornelia Huck
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 03/25] error: Factor out common error setter logic Peter Crosthwaite
2015-09-11 15:30   ` Eric Blake
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 04/25] error: Add support for multiple errors Peter Crosthwaite
2015-09-11 15:49   ` Eric Blake
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 05/25] error: Add error prefix API Peter Crosthwaite
2015-09-11 16:04   ` Eric Blake [this message]
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 06/25] error: Add error_printf_fn() Peter Crosthwaite
2015-09-11 16:10   ` Eric Blake
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 07/25] sysbus: mmio_map+mmio_get_region: ignore range OOB errors Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 08/25] memory: nop APIs when they have NULL arguments Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 09/25] qdev: gpio: Ignore unconnectable GPIOs Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 10/25] arm: xlnx-zynqmp: Update error API usages Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 11/25] arm: fsl-imx*: " Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 12/25] arm: netduino: " Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 13/25] arm: allwinner: " Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 14/25] arm: digic: " Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 15/25] cpu: arm: Remove un-needed error checking Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 16/25] ppc: Update error API usages Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 17/25] i386: pc: " Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 18/25] monitor: update " Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 19/25] qdev: Update " Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 20/25] block: " Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 21/25] tests: " Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 22/25] usb: bus: " Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 23/25] scsi: " Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 24/25] migration: savevm: " Peter Crosthwaite
2015-09-11  5:33 ` [Qemu-devel] [RFC PATCH v1 25/25] core: " Peter Crosthwaite
2015-09-11  6:42 ` [Qemu-devel] [RFC PATCH v1 00/25] error: Automatic error concatenation and prefixing Markus Armbruster
2015-09-11 15:53   ` Eric Blake
2015-09-11 15:27 ` Eric Blake

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=55F2FB92.6020608@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=crosthwaitepeter@gmail.com \
    --cc=peter.maydell@linaro.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).