[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH 1/2] perl: Don't prefix error messages with command name.



On Fri, Feb 12, 2010 at 04:45:33PM +0000, Matthew Booth wrote:
> On 12/02/10 14:43, Richard W.M. Jones wrote:
> >>From 26a2aa2a2b4440e170c51c7ee82cba31d65b78ea Mon Sep 17 00:00:00 2001
> > From: Richard Jones <rjones redhat com>
> > Date: Fri, 12 Feb 2010 13:42:57 +0000
> > Subject: [PATCH 1/2] perl: Don't prefix error messages with command name.
> > 
> > The command name is already being added by the RPC stubs, so
> > adding it again in Perl just results in doubled error messages
> > like:
> >   foo: foo: the error
> > ---
> >  src/generator.ml |   14 +++++++-------
> >  1 files changed, 7 insertions(+), 7 deletions(-)
> > 
> > diff --git a/src/generator.ml b/src/generator.ml
> > index 607b6d1..b0ffc58 100755
> > --- a/src/generator.ml
> > +++ b/src/generator.ml
> > @@ -8149,7 +8149,7 @@ DESTROY (g)
> >             pr ";\n";
> >             do_cleanups ();
> >             pr "      if (r == -1)\n";
> > -           pr "        croak (\"%s: %%s\", guestfs_last_error (g));\n" name;
> > +           pr "        croak (\"%%s\", guestfs_last_error (g));\n";
> 
> If you search for guestfs_last_error in generator.ml, it looks like
> there are more of these. Some examples:
> 
> 8260:
>   do_cleanups ();
>   pr "      if (%s == NULL)\n" n;
>   pr "        croak (\"%s: %%s\", guestfs_last_error (g));\n" name;
> 
> 8304:
>   do_cleanups ();
>   pr "      if (%s == NULL)\n" n;
>   pr "        croak (\"%s: %%s\", guestfs_last_error (g));\n" name;
> 
> 10314:
>       generate_call ();
>       pr "      if (r %s)\n" (c_error_comparison ());
>       pr "        throw new Error (\"%s: \" + guestfs_last_error
> (_handle));\n"
>         name;

Oh dear, indeed there are.

Updated patch attached.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
>From 9b3ef85a3d1b43faa98bb5dc922f8a273a5e1dde Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones redhat com>
Date: Fri, 12 Feb 2010 13:42:57 +0000
Subject: [PATCH 1/2] generator: Don't prefix error messages with command name.

The command name is already being added by the RPC stubs, so
adding it again in Perl and C# just results in doubled error messages
like:
  foo: foo: the error
---
 src/generator.ml |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/generator.ml b/src/generator.ml
index 607b6d1..9cd588b 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -8149,7 +8149,7 @@ DESTROY (g)
            pr ";\n";
            do_cleanups ();
            pr "      if (r == -1)\n";
-           pr "        croak (\"%s: %%s\", guestfs_last_error (g));\n" name;
+           pr "        croak (\"%%s\", guestfs_last_error (g));\n";
        | RInt n
        | RBool n ->
            pr "PREINIT:\n";
@@ -8160,7 +8160,7 @@ DESTROY (g)
            pr ";\n";
            do_cleanups ();
            pr "      if (%s == -1)\n" n;
-           pr "        croak (\"%s: %%s\", guestfs_last_error (g));\n" name;
+           pr "        croak (\"%%s\", guestfs_last_error (g));\n";
            pr "      RETVAL = newSViv (%s);\n" n;
            pr " OUTPUT:\n";
            pr "      RETVAL\n"
@@ -8173,7 +8173,7 @@ DESTROY (g)
            pr ";\n";
            do_cleanups ();
            pr "      if (%s == -1)\n" n;
-           pr "        croak (\"%s: %%s\", guestfs_last_error (g));\n" name;
+           pr "        croak (\"%%s\", guestfs_last_error (g));\n";
            pr "      RETVAL = my_newSVll (%s);\n" n;
            pr " OUTPUT:\n";
            pr "      RETVAL\n"
@@ -8186,7 +8186,7 @@ DESTROY (g)
            pr ";\n";
            do_cleanups ();
            pr "      if (%s == NULL)\n" n;
-           pr "        croak (\"%s: %%s\", guestfs_last_error (g));\n" name;
+           pr "        croak (\"%%s\", guestfs_last_error (g));\n";
            pr "      RETVAL = newSVpv (%s, 0);\n" n;
            pr " OUTPUT:\n";
            pr "      RETVAL\n"
@@ -8213,7 +8213,7 @@ DESTROY (g)
            pr ";\n";
            do_cleanups ();
            pr "      if (%s == NULL)\n" n;
-           pr "        croak (\"%s: %%s\", guestfs_last_error (g));\n" name;
+           pr "        croak (\"%%s\", guestfs_last_error (g));\n";
            pr "      RETVAL = newSVpv (%s, 0);\n" n;
            pr "      free (%s);\n" n;
            pr " OUTPUT:\n";
@@ -8228,7 +8228,7 @@ DESTROY (g)
            pr ";\n";
            do_cleanups ();
            pr "      if (%s == NULL)\n" n;
-           pr "        croak (\"%s: %%s\", guestfs_last_error (g));\n" name;
+           pr "        croak (\"%%s\", guestfs_last_error (g));\n";
            pr "      for (n = 0; %s[n] != NULL; ++n) /**/;\n" n;
            pr "      EXTEND (SP, n);\n";
            pr "      for (i = 0; i < n; ++i) {\n";
@@ -8252,7 +8252,7 @@ DESTROY (g)
            pr ";\n";
            do_cleanups ();
            pr "      if (%s == NULL)\n" n;
-           pr "        croak (\"%s: %%s\", guestfs_last_error (g));\n" name;
+           pr "        croak (\"%%s\", guestfs_last_error (g));\n";
            pr "      RETVAL = newSVpv (%s, size);\n" n;
            pr "      free (%s);\n" n;
            pr " OUTPUT:\n";
@@ -8273,7 +8273,7 @@ and generate_perl_struct_list_code typ cols name style n do_cleanups =
   pr ";\n";
   do_cleanups ();
   pr "      if (%s == NULL)\n" n;
-  pr "        croak (\"%s: %%s\", guestfs_last_error (g));\n" name;
+  pr "        croak (\"%%s\", guestfs_last_error (g));\n";
   pr "      EXTEND (SP, %s->len);\n" n;
   pr "      for (i = 0; i < %s->len; ++i) {\n" n;
   pr "        hv = newHV ();\n";
@@ -8317,7 +8317,7 @@ and generate_perl_struct_code typ cols name style n do_cleanups =
   pr ";\n";
   do_cleanups ();
   pr "      if (%s == NULL)\n" n;
-  pr "        croak (\"%s: %%s\", guestfs_last_error (g));\n" name;
+  pr "        croak (\"%%s\", guestfs_last_error (g));\n";
   pr "      EXTEND (SP, 2 * %d);\n" (List.length cols);
   List.iter (
     fun ((name, _) as col) ->
@@ -10327,8 +10327,7 @@ namespace Guestfs
       pr "      r = ";
       generate_call ();
       pr "      if (r %s)\n" (c_error_comparison ());
-      pr "        throw new Error (\"%s: \" + guestfs_last_error (_handle));\n"
-        name;
+      pr "        throw new Error (guestfs_last_error (_handle));\n";
       (match fst style with
        | RErr -> ()
        | RBool _ ->
-- 
1.6.5.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]