All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-trivial@nongnu.org,
	Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org, Max Reitz <mreitz@redhat.com>,
	John Snow <jsnow@redhat.com>
Subject: Re: [PATCH] block: Remove trailing newline in format used by error_report API
Date: Fri, 28 Feb 2020 18:32:24 +0100	[thread overview]
Message-ID: <8736auipnb.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20200228123637.15160-1-philmd@redhat.com> ("Philippe Mathieu-Daudé"'s message of "Fri, 28 Feb 2020 13:36:37 +0100")

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> The error_report API doesn't want trailing newline characters.
> Remove it, to avoid and error when moving the code around:
>
>   ERROR: Error messages should not contain newlines

Commit 312fd5f2909 has a Coccinelle script.  It should be committed and
re-run.

> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  block.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/block.c b/block.c
> index 1bdb9c679d..e466d15914 100644
> --- a/block.c
> +++ b/block.c
> @@ -5994,7 +5994,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
           bs = bdrv_open(full_backing, NULL, backing_options, back_flags,
                          &local_err);
           g_free(full_backing);
           if (!bs && size != -1) {
>              /* Couldn't open BS, but we have a size, so it's nonfatal */
>              warn_reportf_err(local_err,
>                              "Could not verify backing image. "
> -                            "This may become an error in future versions.\n");
> +                            "This may become an error in future versions.");
>              local_err = NULL;
>          } else if (!bs) {
>              /* Couldn't open bs, do not have size */

warn_reportf_err() is a convenience function to error_prepend(),
warn_report() and free @local_err.

When @local_err holds a message like "pants on fire", the code before
the patch prints something like

    qemu-system-x86_64: warning: Could not verify backing image. This may become an error in future versions.
    pants on fire

The patch "improves" it to

    qemu-system-x86_64: warning: Could not verify backing image. This may become an error in future versions.pants on fire

General advice: this misuse of warn_reportf_err() is an excusable
mistake, but when you *test* the error path, you can't *not* see that
the actual message is crap.  Test your errors!

Actual improvement:

               warn_reportf_err(local_err, "Could not verify backing image: ");
               error_printf("This may become an error in future versions.\n");

This should print

    qemu-system-x86_64: warning: Could not verify backing image: pants on fire
    This may become an error in future versions.



WARNING: multiple messages have this Message-ID (diff)
From: Markus Armbruster <armbru@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org, qemu-trivial@nongnu.org,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
	John Snow <jsnow@redhat.com>
Subject: Re: [PATCH] block: Remove trailing newline in format used by error_report API
Date: Fri, 28 Feb 2020 18:32:24 +0100	[thread overview]
Message-ID: <8736auipnb.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20200228123637.15160-1-philmd@redhat.com> ("Philippe Mathieu-Daudé"'s message of "Fri, 28 Feb 2020 13:36:37 +0100")

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> The error_report API doesn't want trailing newline characters.
> Remove it, to avoid and error when moving the code around:
>
>   ERROR: Error messages should not contain newlines

Commit 312fd5f2909 has a Coccinelle script.  It should be committed and
re-run.

> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  block.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/block.c b/block.c
> index 1bdb9c679d..e466d15914 100644
> --- a/block.c
> +++ b/block.c
> @@ -5994,7 +5994,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
           bs = bdrv_open(full_backing, NULL, backing_options, back_flags,
                          &local_err);
           g_free(full_backing);
           if (!bs && size != -1) {
>              /* Couldn't open BS, but we have a size, so it's nonfatal */
>              warn_reportf_err(local_err,
>                              "Could not verify backing image. "
> -                            "This may become an error in future versions.\n");
> +                            "This may become an error in future versions.");
>              local_err = NULL;
>          } else if (!bs) {
>              /* Couldn't open bs, do not have size */

warn_reportf_err() is a convenience function to error_prepend(),
warn_report() and free @local_err.

When @local_err holds a message like "pants on fire", the code before
the patch prints something like

    qemu-system-x86_64: warning: Could not verify backing image. This may become an error in future versions.
    pants on fire

The patch "improves" it to

    qemu-system-x86_64: warning: Could not verify backing image. This may become an error in future versions.pants on fire

General advice: this misuse of warn_reportf_err() is an excusable
mistake, but when you *test* the error path, you can't *not* see that
the actual message is crap.  Test your errors!

Actual improvement:

               warn_reportf_err(local_err, "Could not verify backing image: ");
               error_printf("This may become an error in future versions.\n");

This should print

    qemu-system-x86_64: warning: Could not verify backing image: pants on fire
    This may become an error in future versions.



  parent reply	other threads:[~2020-02-28 17:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-28 12:36 [PATCH] block: Remove trailing newline in format used by error_report API Philippe Mathieu-Daudé
2020-02-28 12:36 ` Philippe Mathieu-Daudé
2020-02-28 13:16 ` Liam Merwick
2020-02-28 13:16   ` Liam Merwick
2020-02-28 17:32 ` Markus Armbruster [this message]
2020-02-28 17:32   ` Markus Armbruster
2020-06-05 14:26   ` Philippe Mathieu-Daudé
2020-06-05 14:26     ` Philippe Mathieu-Daudé
2020-06-08  4:45     ` Markus Armbruster
2020-06-08  6:14       ` Philippe Mathieu-Daudé

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=8736auipnb.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@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.