Skip to contentSkip to conversation

qemu-option: Include name of invalid parameter in error message

PATCH In review Stefan Weil 2 participants 4 messages Aug 1, 2010 – Aug 20, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-option: Include name of invalid parameter in error message

All other error messages in qemu-option.c display the name of the invalid parameter. This seems to be reasonable for invalid identifiers, too. Without it, a debugger is needed to find the name.

Cc Markus Armbruster <[email protected]>
Cc Anthony Liguori <[email protected]>
---
 qemu-option.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
qemu-option.c +1 -1
index 1f8f41a..ccea267 100644
@@ -694,7 +694,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exist
 
     if (id) {
         if (!id_wellformed(id)) {
-            qerror_report(QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
+            qerror_report(QERR_INVALID_PARAMETER_VALUE, id, "an identifier");
             error_printf_unless_qmp("Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.\n");
             return NULL;
         }
Signature · 1 line
1.7.1
#1 lore raw
Quoted 17 lines · Stefan Weil

All other error messages in qemu-option.c display the name of the invalid parameter. This seems to be reasonable for invalid identifiers, too. Without it, a debugger is needed to find the name.

Cc Markus Armbruster <[email protected]>
Cc Anthony Liguori <[email protected]>
---
 qemu-option.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
qemu-option.c +0 -0
index 1f8f41a..ccea267 100644

qemu-option.c QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exist · line 700

Quoted 8 lines
qemu-option.c +1 -1
@@ -694,7 +694,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exist
 
     if (id) {
         if (!id_wellformed(id)) {
-            qerror_report(QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
+            qerror_report(QERR_INVALID_PARAMETER_VALUE, id, "an identifier");
             error_printf_unless_qmp("Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.\n");
             return NULL;
         }

No.

QERR_INVALID_PARAMETER_VALUE's first argument is the parameter *name*, not the parameter *value*.

In this case, the parameter name is "id". The variable id contains the parameter value.

If you need a debugger to find the offending id=, then location information is lacking. Could you give an example where it's hard to find the offending parameter?

Here's an example where it's easy to find:

    $ qemu-system-x86_64 -device e1000,id=.
    qemu-system-x86_64: -device e1000,id=.: Parameter 'id' expects an identifier
    Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.
#2 lore raw

Am 02.08.2010 10:40, schrieb Markus Armbruster:

Quoted 41 lines
Quoted 19 lines · Stefan Weil

All other error messages in qemu-option.c display the name of the invalid parameter. This seems to be reasonable for invalid identifiers, too. Without it, a debugger is needed to find the name.

Cc Markus Armbruster <[email protected]>
Cc Anthony Liguori <[email protected]>

---
qemu-option.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
qemu-option.c +0 -0
index 1f8f41a..ccea267 100644
@@ -694,7 +694,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, 

const char *id, int fail_if_exist

Quoted 7 lines

if (id) {
if (!id_wellformed(id)) {
- qerror_report(QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
+ qerror_report(QERR_INVALID_PARAMETER_VALUE, id, "an identifier"); error_printf_unless_qmp("Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.\n"); return NULL;
}

No.

QERR_INVALID_PARAMETER_VALUE's first argument is the parameter *name*, not the parameter *value*.

In this case, the parameter name is "id". The variable id contains the parameter value.

If you need a debugger to find the offending id=, then location information is lacking. Could you give an example where it's hard to find the offending parameter?

Quoted 5 lines

Here's an example where it's easy to find:

$ qemu-system-x86_64 -device e1000,id=.
qemu-system-x86_64: -device e1000,id=.: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.

I had a call of qemu_chr_open with an id containing a space (which looks better in the console display where the id is shown) in my ar7 emulation. You can test this scenario using this patch:

vl.c +1 -1
@@ -1700,7 +1700,7 @@ static int serial_parse(const char *devname)
         fprintf(stderr, "qemu: too many serial ports\n");
         exit(1);
     }
-    snprintf(label, sizeof(label), "serial%d", index);
+    snprintf(label, sizeof(label), "serial %d", index);
     serial_hds[index] = qemu_chr_open(label, devname, NULL);
     if (!serial_hds[index]) {
         fprintf(stderr, "qemu: could not open serial device '%s': %s\n",

It results in these error messages:

qemu: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.
qemu: could not open serial device 'vc:80Cx24C': No such file or directory

The "location information" is indeed missing. For this kind of error, an assertion would be better than an error message.

#3 lore raw
Quoted 69 lines · Stefan Weil

Am 02.08.2010 10:40, schrieb Markus Armbruster:

Quoted 42 lines
Quoted 19 lines · Stefan Weil

All other error messages in qemu-option.c display the name of the invalid parameter. This seems to be reasonable for invalid identifiers, too. Without it, a debugger is needed to find the name.

Cc Markus Armbruster <[email protected]>
Cc Anthony Liguori <[email protected]>

---
qemu-option.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
qemu-option.c +0 -0
index 1f8f41a..ccea267 100644
@@ -694,7 +694,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list,

const char *id, int fail_if_exist

Quoted 8 lines

if (id) {
if (!id_wellformed(id)) {
- qerror_report(QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
+ qerror_report(QERR_INVALID_PARAMETER_VALUE, id, "an identifier"); error_printf_unless_qmp("Identifiers consist of letters, digits, -', '.', '_', starting with a letter.\n");
return NULL;
}

No.

QERR_INVALID_PARAMETER_VALUE's first argument is the parameter *name*, not the parameter *value*.

In this case, the parameter name is "id". The variable id contains the parameter value.

If you need a debugger to find the offending id=, then location information is lacking. Could you give an example where it's hard to find the offending parameter?

Quoted 7 lines

Here's an example where it's easy to find:

$ qemu-system-x86_64 -device e1000,id=.
qemu-system-x86_64: -device e1000,id=.: Parameter 'id' expects an
identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with
a letter.

I had a call of qemu_chr_open with an id containing a space (which looks better in the console display where the id is shown) in my ar7 emulation. You can test this scenario using this patch:

vl.c +1 -1
@@ -1700,7 +1700,7 @@ static int serial_parse(const char *devname)
         fprintf(stderr, "qemu: too many serial ports\n");
         exit(1);
     }
-    snprintf(label, sizeof(label), "serial%d", index);
+    snprintf(label, sizeof(label), "serial %d", index);
     serial_hds[index] = qemu_chr_open(label, devname, NULL);
     if (!serial_hds[index]) {
         fprintf(stderr, "qemu: could not open serial device '%s': %s\n",

It results in these error messages:

Quoted 7 lines

qemu: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.
qemu: could not open serial device 'vc:80Cx24C': No such file or directory

The "location information" is indeed missing. For this kind of error, an assertion would be better than an error message.

I agree that programming errors should not be reported as user errors.

Down where the error is detected, the code doesn't know whether it's processing hardcoded arguments (programming error), or whether it's processing user arguments (user error).

The best we can do with relative ease is report the error assuming it's a user error, and return failure up the call chain. When we reach hardcoded-land, report the programming error.