Skip to contentSkip to conversation

numa: clarify error message when node index is out of range in -numa dist, ...

PATCH Superseded Igor Mammedov 4 participants 7 messages May 15, 2018 – May 16, 2018

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 numa: clarify error message when node index is out of range in -numa dist, ...

When using following CLI:
-numa dist,src=128,dst=1,val=20
user gets a rather confusing error message:
"Invalid node 128, max possible could be 128"

Where 128 is number of nodes that QEMU supports (MAX_NODES), while src/dst is an index up to that limit, so it should be MAX_NODES - 1 in error message.
Make error message to explicitly state valid range for node index to be more clear.

---
 numa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
numa.c +2 -2
index a3637cc..9f0c49f 100644
@@ -142,8 +142,8 @@ static void parse_numa_distance(NumaDistOptions *dist, Error **errp)
 
     if (src >= MAX_NODES || dst >= MAX_NODES) {
         error_setg(errp,
-                   "Invalid node %d, max possible could be %d",
-                   MAX(src, dst), MAX_NODES);
+                   "Invalid node %d, The valid node range is [0 - %d]",
+                   MAX(src, dst), MAX_NODES - 1);
         return;
     }
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 22 lines · Igor Mammedov

When using following CLI:
-numa dist,src=128,dst=1,val=20
user gets a rather confusing error message:
"Invalid node 128, max possible could be 128"

Where 128 is number of nodes that QEMU supports (MAX_NODES), while src/dst is an index up to that limit, so it should be MAX_NODES - 1 in error message.
Make error message to explicitly state valid range for node index to be more clear.

---
 numa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
numa.c +0 -0
index a3637cc..9f0c49f 100644

numa.c static void parse_numa_distance(NumaDistOptions *dist, Error **errp) · line 145

Quoted 6 lines
numa.c +1 -2
@@ -142,8 +142,8 @@ static void parse_numa_distance(NumaDistOptions *dist, Error **errp)
 
     if (src >= MAX_NODES || dst >= MAX_NODES) {
         error_setg(errp,
-                   "Invalid node %d, max possible could be %d",
-                   MAX(src, dst), MAX_NODES);
+                   "Invalid node %d, The valid node range is [0 - %d]",

^ should be a '.'

And maybe need a '.' at the end of the second sentence too, as it's not an error phrase, but a real sentence.

Quoted 7 lines
numa.c +1 -0
+                   MAX(src, dst), MAX_NODES - 1);
         return;
     }
 
Signature · 1 line
2.7.4
#2 lore raw

PATCH v3 1/1 numa: clarify error message when node index is out of range in -numa dist, ...

When using following CLI:
-numa dist,src=128,dst=1,val=20
user gets a rather confusing error message:
"Invalid node 128, max possible could be 128"

Where 128 is number of nodes that QEMU supports (MAX_NODES), while src/dst is an index up to that limit, so it should be MAX_NODES - 1 in error message.
Make error message to explicitly state valid range for node index to be more clear.

---
v3:
- s/,/./ in error message
- add '.' at the end of sentence

---
 numa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
numa.c +2 -2
index 188bfdf..d98c106 100644
@@ -142,8 +142,8 @@ static void parse_numa_distance(NumaDistOptions *dist, Error **errp)
 
     if (src >= MAX_NODES || dst >= MAX_NODES) {
         error_setg(errp,
-                   "Invalid node %d, max possible could be %d",
-                   MAX(src, dst), MAX_NODES);
+                   "Invalid node %d. The valid node range is [0 - %d].",
+                   MAX(src, dst), MAX_NODES - 1);
         return;
     }
 
Signature · 1 line
2.7.4
#3 lore raw
In reply to Andrew Jones
Quoted 21 lines · Andrew Jones
Quoted 17 lines · Igor Mammedov

When using following CLI:

   -numa dist,src=128,dst=1,val=20

user gets a rather confusing error message:
"Invalid node 128, max possible could be 128"

Where 128 is number of nodes that QEMU supports (MAX_NODES), while src/dst is an index up to that limit, so it should be MAX_NODES - 1 in error message.
Make error message to explicitly state valid range for node index to be more clear.

---

      if (src >= MAX_NODES || dst >= MAX_NODES) {
          error_setg(errp,

numa.c static void parse_numa_distance(NumaDistOptions *dist, Error **errp) · line 145

Quoted 3 lines
numa.c +1 -2
-                   "Invalid node %d, max possible could be %d",
-                   MAX(src, dst), MAX_NODES);
+                   "Invalid node %d, The valid node range is [0 - %d]",
Quoted 4 lines

^ should be a '.'

And maybe need a '.' at the end of the second sentence too, as it's not an error phrase, but a real sentence.

Actually, error_setg() is documented as taking a single phrase (no '.' included), and that if you need a second sentence, it's better to use error_append_hint(). Maybe Markus has an opinion on the best way to word this error message.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#4 lore raw
Quoted 27 lines · Eric Blake
Quoted 26 lines · Andrew Jones
Quoted 17 lines · Igor Mammedov

When using following CLI:

   -numa dist,src=128,dst=1,val=20

user gets a rather confusing error message:
"Invalid node 128, max possible could be 128"

Where 128 is number of nodes that QEMU supports (MAX_NODES), while src/dst is an index up to that limit, so it should be MAX_NODES - 1 in error message.
Make error message to explicitly state valid range for node index to be more clear.

---

      if (src >= MAX_NODES || dst >= MAX_NODES) {
          error_setg(errp,

numa.c static void parse_numa_distance(NumaDistOptions *dist, Error **errp) · line 145

Quoted 3 lines
numa.c +1 -2
-                   "Invalid node %d, max possible could be %d",
-                   MAX(src, dst), MAX_NODES);
+                   "Invalid node %d, The valid node range is [0 - %d]",

^ should be a '.'

And maybe need a '.' at the end of the second sentence too, as it's not an error phrase, but a real sentence.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
+                   MAX(src, dst), MAX_NODES - 1);
         return;
     }

Actually, error_setg() is documented as taking a single phrase (no '.' included), and that if you need a second sentence, it's better to use error_append_hint().

Correct. Providing help on valid values is exactly what error_append_hint() is for.

Quoted 2 lines

Maybe Markus has an opinion on the best way to
word this error message.

Yes: "Parameter 'src' expects an integer between 0 and 127"

Referring to an erroneous key=value by value is not nice. What if the value occurs in multiple places, and is valid in at least one? key is there, it's unique[*], so use it.

[*] Except in the few places that use repeated keys to form lists. Ugh.

#5 lore raw
Quoted 29 lines · On Tue, 15 May 2018 19:37:02 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 27 lines · Eric Blake
Quoted 26 lines · Andrew Jones
Quoted 17 lines · Igor Mammedov

When using following CLI:

   -numa dist,src=128,dst=1,val=20

user gets a rather confusing error message:
"Invalid node 128, max possible could be 128"

Where 128 is number of nodes that QEMU supports (MAX_NODES), while src/dst is an index up to that limit, so it should be MAX_NODES - 1 in error message.
Make error message to explicitly state valid range for node index to be more clear.

---

      if (src >= MAX_NODES || dst >= MAX_NODES) {
          error_setg(errp,

numa.c static void parse_numa_distance(NumaDistOptions *dist, Error **errp) · line 145

Quoted 3 lines
numa.c +1 -2
-                   "Invalid node %d, max possible could be %d",
-                   MAX(src, dst), MAX_NODES);
+                   "Invalid node %d, The valid node range is [0 - %d]",  

^ should be a '.'

And maybe need a '.' at the end of the second sentence too, as it's not an error phrase, but a real sentence.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
+                   MAX(src, dst), MAX_NODES - 1);
         return;
     }  

Actually, error_setg() is documented as taking a single phrase (no '.' included), and that if you need a second sentence, it's better to use error_append_hint().

well, using append_hint makes it less readable, before using it we get following error:

$ qemu-system-x86_64 -numa dist,src=128,dst=1,val=20
qemu-system-x86_64: -numa dist,src=128,dst=1,val=20: Invalid node 128, The valid node range is [0 - 127]
$

after using it we get:

$ qemu-system-x86_64 -numa dist,src=128,dst=1,val=20
qemu-system-x86_64: -numa dist,src=128,dst=1,val=20: Invalid node value 128
The valid node range is [0 - 127]$ 

i.e. an extra newline in the middle of error message and looses automatic newline at the end so the shell prompt continues error message

Quoted 14 lines

Correct. Providing help on valid values is exactly what error_append_hint() is for.

Quoted 2 lines

Maybe Markus has an opinion on the best way to
word this error message.

Yes: "Parameter 'src' expects an integer between 0 and 127"

Referring to an erroneous key=value by value is not nice. What if the value occurs in multiple places, and is valid in at least one? key is there, it's unique[*], so use it.

[*] Except in the few places that use repeated keys to form lists. Ugh.

#6 lore raw
Quoted 9 lines · Igor Mammedov
Quoted 3 lines
Quoted 3 lines

Actually, error_setg() is documented as taking a single phrase (no '.' included), and that if you need a second sentence, it's better to use error_append_hint().

well, using append_hint makes it less readable, before using it we get following error:

$ qemu-system-x86_64 -numa dist,src=128,dst=1,val=20
qemu-system-x86_64: -numa dist,src=128,dst=1,val=20: Invalid node 128, The valid node range is [0 - 127]
$
Quoted 9 lines

after using it we get:

$ qemu-system-x86_64 -numa dist,src=128,dst=1,val=20
qemu-system-x86_64: -numa dist,src=128,dst=1,val=20: Invalid node value 128
The valid node range is [0 - 127]$

i.e. an extra newline in the middle of error message and looses automatic newline at the end so the shell prompt continues error message

Use of error_append_hint() requires you to provide a newline (unlike error_setg(). But as Markus pointed out, you don't need to use it:

Quoted 8 lines
Quoted 8 lines

Correct. Providing help on valid values is exactly what error_append_hint() is for.

Quoted 2 lines

Maybe Markus has an opinion on the best way to
word this error message.

Yes: "Parameter 'src' expects an integer between 0 and 127"

I like this wording better, which avoids the shortfalls that error_append_hint() would introduce.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org