From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45877) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQ9x7-00087x-Rb for qemu-devel@nongnu.org; Thu, 21 Jul 2016 05:07:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQ9x5-00011e-Kq for qemu-devel@nongnu.org; Thu, 21 Jul 2016 05:07:32 -0400 Date: Thu, 21 Jul 2016 10:07:21 +0100 From: Stefan Hajnoczi Message-ID: <20160721090721.GA27488@stefanha-x1.localdomain> References: <20160721084153.16103-1-fullmanet@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="/04w6evG8XlLl3ft" Content-Disposition: inline In-Reply-To: <20160721084153.16103-1-fullmanet@gmail.com> Subject: Re: [Qemu-devel] [PATCH] qemu-img: fix error messages emitted by img_open() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Reda Sallahi Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Kevin Wolf , Max Reitz , Fam Zheng , qemu-trivial@nongnu.org --/04w6evG8XlLl3ft Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jul 21, 2016 at 10:41:53AM +0200, Reda Sallahi wrote: > img_open_file() and img_open_opts() were printing error messages with a > duplicate part because of a wrong use of error_reportf_err() (e.g. > qemu-img: Could not open 'foo': Could not open 'foo': No such file or dir= ectory) >=20 > This change uses error_report_err() instead to eliminate the duplicate pa= rt. >=20 > Signed-off-by: Reda Sallahi > --- > qemu-img.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) >=20 > diff --git a/qemu-img.c b/qemu-img.c > index 2e40e1f..dc6652d 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -268,7 +268,7 @@ static BlockBackend *img_open_opts(const char *optstr, > options =3D qemu_opts_to_qdict(opts, NULL); > blk =3D blk_new_open(NULL, NULL, options, flags, &local_err); > if (!blk) { > - error_reportf_err(local_err, "Could not open '%s': ", optstr); > + error_report_err(local_err); > return NULL; > } > blk_set_enable_write_cache(blk, !writethrough); > @@ -295,7 +295,7 @@ static BlockBackend *img_open_file(const char *filena= me, > =20 > blk =3D blk_new_open(filename, NULL, options, flags, &local_err); > if (!blk) { > - error_reportf_err(local_err, "Could not open '%s': ", filename); > + error_report(local_err); > return NULL; > } > blk_set_enable_write_cache(blk, !writethrough); The duplication happens in the "Could not open 'foo'" case, but other error cases do not include the filename in the error message. We would lose information in those error cases since the filename is no longer included by qemu-img.c in the error message. I'm not aware of a clean way to distinguish Error objects. Maybe someone else can suggest one. Otherwise it may be best to leave the code as it is. Stefan --/04w6evG8XlLl3ft Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJXkJDJAAoJEJykq7OBq3PIk2oH/1AHdz4WC7aJ0bEo3dQytyS+ uD1UrCcNlP/Hg+tShU1A4ok95BDITB2VIDmGwdbDZaAb1p+rdv2YgnziXPklutvk CF6trFsMw9hj/mmshBOPaOHuX23GvPf9i4QMd1CutYGZ5gXVKjXECQVxxuJ4twU4 y+5r+zJaAuj2Ic1s3PZPb1tkq/uFbis962PcB7SLyIGfFpT3koV7vGa/ae2ukVvN AFa3DAEYac3+eLw10F65wb0Uwkk+KZCRBdyW+e8TgLjw8GR/uBJZ2jshZAUCK2jV jyBqj/OxGIwmEBrwqc4Y5kva0ykYHmLM1vZ0m8XkircSd3Pz9RGBYuGr5rruv5g= =ATvb -----END PGP SIGNATURE----- --/04w6evG8XlLl3ft--