Skip to contentSkip to conversation

monitor: print the invalid char in error message

PATCH Applied Fam Zheng 4 participants 4 messages Aug 20, 2013

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH v2 1/1 monitor: print the invalid char in error message

It's more friendly to print which char is invalid to user, especially when user tries to input a float value and expect the monitor to round it to int. Since we don't round float number when we look for a integer, telling which char is invalid is less confusing.

---
 monitor.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
monitor.c +7 -3
index 5dc0aa9..da9c9a2 100644
@@ -3171,9 +3171,13 @@ static const MonitorDef monitor_defs[] = {
     { NULL },
 };
 
-static void expr_error(Monitor *mon, const char *msg)
+static void expr_error(Monitor *mon, const char *fmt, ...)
 {
-    monitor_printf(mon, "%s\n", msg);
+    va_list ap;
+    va_start(ap, fmt);
+    monitor_vprintf(mon, fmt, ap);
+    monitor_printf(mon, "\n");
+    va_end(ap);
     siglongjmp(expr_env, 1);
 }
 
@@ -3291,7 +3295,7 @@ static int64_t expr_unary(Monitor *mon)
             expr_error(mon, "number too large");
         }
         if (pch == p) {
-            expr_error(mon, "invalid char in expression");
+            expr_error(mon, "invalid char '%c' in expression", *p);
         }
         pch = p;
         while (qemu_isspace(*pch))
Signature · 1 line
1.8.3.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 31 lines · Fam Zheng

It's more friendly to print which char is invalid to user, especially when user tries to input a float value and expect the monitor to round it to int. Since we don't round float number when we look for a integer, telling which char is invalid is less confusing.

---
 monitor.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
monitor.c +6 -2
index 5dc0aa9..da9c9a2 100644
@@ -3171,9 +3171,13 @@ static const MonitorDef monitor_defs[] = {
     { NULL },
 };
 
-static void expr_error(Monitor *mon, const char *msg)
+static void expr_error(Monitor *mon, const char *fmt, ...)
 {
-    monitor_printf(mon, "%s\n", msg);
+    va_list ap;
+    va_start(ap, fmt);
+    monitor_vprintf(mon, fmt, ap);
+    monitor_printf(mon, "\n");
+    va_end(ap);
     siglongjmp(expr_env, 1);
 }
 

monitor.c static int64_t expr_unary(Monitor *mon) · line 3301

Quoted 8 lines
monitor.c +1 -1
@@ -3291,7 +3295,7 @@ static int64_t expr_unary(Monitor *mon)
             expr_error(mon, "number too large");
         }
         if (pch == p) {
-            expr_error(mon, "invalid char in expression");
+            expr_error(mon, "invalid char '%c' in expression", *p);
         }
         pch = p;
         while (qemu_isspace(*pch))

The user is still left guessing *where* the error is. But it's an incremental improvement.

Reviewed-by on v2 1/1
#2 lore raw
In reply to Fam Zheng
Quoted 4 lines · Fam Zheng

It's more friendly to print which char is invalid to user, especially when user tries to input a float value and expect the monitor to round it to int. Since we don't round float number when we look for a integer, telling which char is invalid is less confusing.

Including a sample of the error message issued before and after this patch as part of the commit message is helpful, but not enough for me to require a respin.

Quoted 5 lines
---
 monitor.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw
In reply to Fam Zheng
Quoted 6 lines · On Tue, 20 Aug 2013 10:58:21 +0800 Fam Zheng <[email protected]> wrote:

It's more friendly to print which char is invalid to user, especially when user tries to input a float value and expect the monitor to round it to int. Since we don't round float number when we look for a integer, telling which char is invalid is less confusing.

Applied to the qmp branch, thanks.

Quoted 33 lines
---
 monitor.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
monitor.c +7 -3
index 5dc0aa9..da9c9a2 100644
@@ -3171,9 +3171,13 @@ static const MonitorDef monitor_defs[] = {
     { NULL },
 };
 
-static void expr_error(Monitor *mon, const char *msg)
+static void expr_error(Monitor *mon, const char *fmt, ...)
 {
-    monitor_printf(mon, "%s\n", msg);
+    va_list ap;
+    va_start(ap, fmt);
+    monitor_vprintf(mon, fmt, ap);
+    monitor_printf(mon, "\n");
+    va_end(ap);
     siglongjmp(expr_env, 1);
 }
 
@@ -3291,7 +3295,7 @@ static int64_t expr_unary(Monitor *mon)
             expr_error(mon, "number too large");
         }
         if (pch == p) {
-            expr_error(mon, "invalid char in expression");
+            expr_error(mon, "invalid char '%c' in expression", *p);
         }
         pch = p;
         while (qemu_isspace(*pch))