diff mbox

[v2,3/3] qemu-io: Correct error messages

Message ID 1445903114-22566-4-git-send-email-jsnow@redhat.com
State New
Headers show

Commit Message

John Snow Oct. 26, 2015, 11:45 p.m. UTC
Reported-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 qemu-io-cmds.c | 53 ++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 34 insertions(+), 19 deletions(-)

Comments

Eric Blake Oct. 27, 2015, 2:26 a.m. UTC | #1
On 10/26/2015 05:45 PM, John Snow wrote:
> Reported-by: Max Reitz <mreitz@redhat.com>
> Signed-off-by: John Snow <jsnow@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> ---
>  qemu-io-cmds.c | 53 ++++++++++++++++++++++++++++++++++-------------------
>  1 file changed, 34 insertions(+), 19 deletions(-)
> 
> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
> index 44d24e8..92c6b87 100644
> --- a/qemu-io-cmds.c
> +++ b/qemu-io-cmds.c
> @@ -146,6 +146,21 @@ static int64_t cvtnum(const char *s)
>      return ret;
>  }
>  
> +static void print_cvtnum_err(int64_t rc, const char *arg)
> +{
> +    switch (rc) {
> +    case -EINVAL:
> +        printf("Parsing error: non-numeric argument,"
> +               " or extraneous/unrecognized suffix -- %s\n", arg);
> +        break;
> +    case -ERANGE:
> +        printf("Parsing error: argument too large -- %s\n", arg);
> +        break;
> +    default:
> +        printf("Parsing error -- %s\n", arg);

I still think ':' is better than ' --' in error messages, but I'll leave
it up to the maintainer.
Kevin Wolf Oct. 27, 2015, 11:05 a.m. UTC | #2
Am 27.10.2015 um 00:45 hat John Snow geschrieben:
> Reported-by: Max Reitz <mreitz@redhat.com>
> Signed-off-by: John Snow <jsnow@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>

Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Kevin Wolf Oct. 27, 2015, 11:08 a.m. UTC | #3
Am 27.10.2015 um 03:26 hat Eric Blake geschrieben:
> On 10/26/2015 05:45 PM, John Snow wrote:
> > Reported-by: Max Reitz <mreitz@redhat.com>
> > Signed-off-by: John Snow <jsnow@redhat.com>
> > Reviewed-by: Eric Blake <eblake@redhat.com>
> > ---
> >  qemu-io-cmds.c | 53 ++++++++++++++++++++++++++++++++++-------------------
> >  1 file changed, 34 insertions(+), 19 deletions(-)
> > 
> > diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
> > index 44d24e8..92c6b87 100644
> > --- a/qemu-io-cmds.c
> > +++ b/qemu-io-cmds.c
> > @@ -146,6 +146,21 @@ static int64_t cvtnum(const char *s)
> >      return ret;
> >  }
> >  
> > +static void print_cvtnum_err(int64_t rc, const char *arg)
> > +{
> > +    switch (rc) {
> > +    case -EINVAL:
> > +        printf("Parsing error: non-numeric argument,"
> > +               " or extraneous/unrecognized suffix -- %s\n", arg);
> > +        break;
> > +    case -ERANGE:
> > +        printf("Parsing error: argument too large -- %s\n", arg);
> > +        break;
> > +    default:
> > +        printf("Parsing error -- %s\n", arg);
> 
> I still think ':' is better than ' --' in error messages, but I'll leave
> it up to the maintainer.

This isn't important enough for a maintainer decision - if this isn't
something that the patch submitter can decide by himself, what else
would be left? In particular because the patch only retains the existing
format. I'm happy to merge a patch that uses colons instead, but I won't
reject anything just because it doesn't do the conversion.

Kevin
John Snow Oct. 27, 2015, 3:50 p.m. UTC | #4
On 10/26/2015 10:26 PM, Eric Blake wrote:
> On 10/26/2015 05:45 PM, John Snow wrote:
>> Reported-by: Max Reitz <mreitz@redhat.com>
>> Signed-off-by: John Snow <jsnow@redhat.com>
>> Reviewed-by: Eric Blake <eblake@redhat.com>
>> ---
>>  qemu-io-cmds.c | 53 ++++++++++++++++++++++++++++++++++-------------------
>>  1 file changed, 34 insertions(+), 19 deletions(-)
>>
>> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
>> index 44d24e8..92c6b87 100644
>> --- a/qemu-io-cmds.c
>> +++ b/qemu-io-cmds.c
>> @@ -146,6 +146,21 @@ static int64_t cvtnum(const char *s)
>>      return ret;
>>  }
>>  
>> +static void print_cvtnum_err(int64_t rc, const char *arg)
>> +{
>> +    switch (rc) {
>> +    case -EINVAL:
>> +        printf("Parsing error: non-numeric argument,"
>> +               " or extraneous/unrecognized suffix -- %s\n", arg);
>> +        break;
>> +    case -ERANGE:
>> +        printf("Parsing error: argument too large -- %s\n", arg);
>> +        break;
>> +    default:
>> +        printf("Parsing error -- %s\n", arg);
> 
> I still think ':' is better than ' --' in error messages, but I'll leave
> it up to the maintainer.
> 

Crud, sorry Eric -- I didn't do this on purpose. As Kevin notes, I was
just trying to match the existing format. I can change it and send again
if you want. Whatever is easiest for people.

--js
Kevin Wolf Oct. 27, 2015, 4:02 p.m. UTC | #5
Am 27.10.2015 um 16:50 hat John Snow geschrieben:
> 
> 
> On 10/26/2015 10:26 PM, Eric Blake wrote:
> > On 10/26/2015 05:45 PM, John Snow wrote:
> >> Reported-by: Max Reitz <mreitz@redhat.com>
> >> Signed-off-by: John Snow <jsnow@redhat.com>
> >> Reviewed-by: Eric Blake <eblake@redhat.com>
> >> ---
> >>  qemu-io-cmds.c | 53 ++++++++++++++++++++++++++++++++++-------------------
> >>  1 file changed, 34 insertions(+), 19 deletions(-)
> >>
> >> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
> >> index 44d24e8..92c6b87 100644
> >> --- a/qemu-io-cmds.c
> >> +++ b/qemu-io-cmds.c
> >> @@ -146,6 +146,21 @@ static int64_t cvtnum(const char *s)
> >>      return ret;
> >>  }
> >>  
> >> +static void print_cvtnum_err(int64_t rc, const char *arg)
> >> +{
> >> +    switch (rc) {
> >> +    case -EINVAL:
> >> +        printf("Parsing error: non-numeric argument,"
> >> +               " or extraneous/unrecognized suffix -- %s\n", arg);
> >> +        break;
> >> +    case -ERANGE:
> >> +        printf("Parsing error: argument too large -- %s\n", arg);
> >> +        break;
> >> +    default:
> >> +        printf("Parsing error -- %s\n", arg);
> > 
> > I still think ':' is better than ' --' in error messages, but I'll leave
> > it up to the maintainer.
> 
> Crud, sorry Eric -- I didn't do this on purpose. As Kevin notes, I was
> just trying to match the existing format. I can change it and send again
> if you want. Whatever is easiest for people.

I think you need to respin for patch 1 anyway, so changing it in the
next version sounds good. You can keep my R-b when doing this.

Kevin
Eric Blake Oct. 27, 2015, 4:07 p.m. UTC | #6
On 10/27/2015 09:50 AM, John Snow wrote:

>>> +    default:
>>> +        printf("Parsing error -- %s\n", arg);
>>
>> I still think ':' is better than ' --' in error messages, but I'll leave
>> it up to the maintainer.
>>
> 
> Crud, sorry Eric -- I didn't do this on purpose. As Kevin notes, I was
> just trying to match the existing format. I can change it and send again
> if you want. Whatever is easiest for people.

And Kevin has a valid point that you just did code motion, so keeping --
is no worse than before.  At this point, I'll leave it up to you; my R-b
stands either way.
diff mbox

Patch

diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 44d24e8..92c6b87 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -146,6 +146,21 @@  static int64_t cvtnum(const char *s)
     return ret;
 }
 
+static void print_cvtnum_err(int64_t rc, const char *arg)
+{
+    switch (rc) {
+    case -EINVAL:
+        printf("Parsing error: non-numeric argument,"
+               " or extraneous/unrecognized suffix -- %s\n", arg);
+        break;
+    case -ERANGE:
+        printf("Parsing error: argument too large -- %s\n", arg);
+        break;
+    default:
+        printf("Parsing error -- %s\n", arg);
+    }
+}
+
 #define EXABYTES(x)     ((long long)(x) << 60)
 #define PETABYTES(x)    ((long long)(x) << 50)
 #define TERABYTES(x)    ((long long)(x) << 40)
@@ -366,13 +381,13 @@  create_iovec(BlockBackend *blk, QEMUIOVector *qiov, char **argv, int nr_iov,
 
         len = cvtnum(arg);
         if (len < 0) {
-            printf("non-numeric length argument -- %s\n", arg);
+            print_cvtnum_err(len, arg);
             goto fail;
         }
 
         /* should be SIZE_T_MAX, but that doesn't exist */
         if (len > INT_MAX) {
-            printf("too large length argument -- %s\n", arg);
+            printf("Argument '%s' exceeds maximum size %d\n", arg, INT_MAX);
             goto fail;
         }
 
@@ -667,7 +682,7 @@  static int read_f(BlockBackend *blk, int argc, char **argv)
             lflag = 1;
             pattern_count = cvtnum(optarg);
             if (pattern_count < 0) {
-                printf("non-numeric length argument -- %s\n", optarg);
+                print_cvtnum_err(pattern_count, optarg);
                 return 0;
             }
             break;
@@ -688,7 +703,7 @@  static int read_f(BlockBackend *blk, int argc, char **argv)
             sflag = 1;
             pattern_offset = cvtnum(optarg);
             if (pattern_offset < 0) {
-                printf("non-numeric length argument -- %s\n", optarg);
+                print_cvtnum_err(pattern_offset, optarg);
                 return 0;
             }
             break;
@@ -711,14 +726,14 @@  static int read_f(BlockBackend *blk, int argc, char **argv)
 
     offset = cvtnum(argv[optind]);
     if (offset < 0) {
-        printf("non-numeric length argument -- %s\n", argv[optind]);
+        print_cvtnum_err(offset, argv[optind]);
         return 0;
     }
 
     optind++;
     count = cvtnum(argv[optind]);
     if (count < 0) {
-        printf("non-numeric length argument -- %s\n", argv[optind]);
+        print_cvtnum_err(count, argv[optind]);
         return 0;
     }
 
@@ -869,7 +884,7 @@  static int readv_f(BlockBackend *blk, int argc, char **argv)
 
     offset = cvtnum(argv[optind]);
     if (offset < 0) {
-        printf("non-numeric length argument -- %s\n", argv[optind]);
+        print_cvtnum_err(offset, argv[optind]);
         return 0;
     }
     optind++;
@@ -1018,14 +1033,14 @@  static int write_f(BlockBackend *blk, int argc, char **argv)
 
     offset = cvtnum(argv[optind]);
     if (offset < 0) {
-        printf("non-numeric length argument -- %s\n", argv[optind]);
+        print_cvtnum_err(offset, argv[optind]);
         return 0;
     }
 
     optind++;
     count = cvtnum(argv[optind]);
     if (count < 0) {
-        printf("non-numeric length argument -- %s\n", argv[optind]);
+        print_cvtnum_err(count, argv[optind]);
         return 0;
     }
 
@@ -1150,7 +1165,7 @@  static int writev_f(BlockBackend *blk, int argc, char **argv)
 
     offset = cvtnum(argv[optind]);
     if (offset < 0) {
-        printf("non-numeric length argument -- %s\n", argv[optind]);
+        print_cvtnum_err(offset, argv[optind]);
         return 0;
     }
     optind++;
@@ -1277,7 +1292,7 @@  static int multiwrite_f(BlockBackend *blk, int argc, char **argv)
         /* Read the offset of the request */
         offset = cvtnum(argv[optind]);
         if (offset < 0) {
-            printf("non-numeric offset argument -- %s\n", argv[optind]);
+            print_cvtnum_err(offset, argv[optind]);
             goto out;
         }
         optind++;
@@ -1504,7 +1519,7 @@  static int aio_read_f(BlockBackend *blk, int argc, char **argv)
 
     ctx->offset = cvtnum(argv[optind]);
     if (ctx->offset < 0) {
-        printf("non-numeric length argument -- %s\n", argv[optind]);
+        print_cvtnum_err(ctx->offset, argv[optind]);
         g_free(ctx);
         return 0;
     }
@@ -1599,7 +1614,7 @@  static int aio_write_f(BlockBackend *blk, int argc, char **argv)
 
     ctx->offset = cvtnum(argv[optind]);
     if (ctx->offset < 0) {
-        printf("non-numeric length argument -- %s\n", argv[optind]);
+        print_cvtnum_err(ctx->offset, argv[optind]);
         g_free(ctx);
         return 0;
     }
@@ -1659,7 +1674,7 @@  static int truncate_f(BlockBackend *blk, int argc, char **argv)
 
     offset = cvtnum(argv[1]);
     if (offset < 0) {
-        printf("non-numeric truncate argument -- %s\n", argv[1]);
+        print_cvtnum_err(offset, argv[1]);
         return 0;
     }
 
@@ -1806,14 +1821,14 @@  static int discard_f(BlockBackend *blk, int argc, char **argv)
 
     offset = cvtnum(argv[optind]);
     if (offset < 0) {
-        printf("non-numeric length argument -- %s\n", argv[optind]);
+        print_cvtnum_err(offset, argv[optind]);
         return 0;
     }
 
     optind++;
     count = cvtnum(argv[optind]);
     if (count < 0) {
-        printf("non-numeric length argument -- %s\n", argv[optind]);
+        print_cvtnum_err(count, argv[optind]);
         return 0;
     }
 
@@ -1847,7 +1862,7 @@  static int alloc_f(BlockBackend *blk, int argc, char **argv)
 
     offset = cvtnum(argv[1]);
     if (offset < 0) {
-        printf("non-numeric offset argument -- %s\n", argv[1]);
+        print_cvtnum_err(offset, argv[1]);
         return 0;
     } else if (offset & 0x1ff) {
         printf("offset %" PRId64 " is not sector aligned\n",
@@ -1858,7 +1873,7 @@  static int alloc_f(BlockBackend *blk, int argc, char **argv)
     if (argc == 3) {
         nb_sectors = cvtnum(argv[2]);
         if (nb_sectors < 0) {
-            printf("non-numeric length argument -- %s\n", argv[2]);
+            print_cvtnum_err(nb_sectors, argv[2]);
             return 0;
         }
     } else {
@@ -2199,7 +2214,7 @@  static int sigraise_f(BlockBackend *blk, int argc, char **argv)
 {
     int64_t sig = cvtnum(argv[1]);
     if (sig < 0) {
-        printf("non-numeric signal number argument -- %s\n", argv[1]);
+        print_cvtnum_err(sig, argv[1]);
         return 0;
     } else if (sig > NSIG) {
         printf("signal argument '%s' is too large to be a valid signal\n",