error: More error_setg() usage

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABAgAGBQJWQ4F7AAoJEDhwtADrkYZTfLwP/RQrScyqDdJamcXGY1vgtoKW
 2SgkGsx9zS8EwFpROugi5d4YeQItU469PI9KAK8Xlt+qsRqOmAlWAGwBp9s78bs5
 P9BYNISdhpF2YcRWBz01rk8PqW80P30dwpCNJQtG/xMv2fGoqFm7/OlFLuv1rfXi
 G/Yo5qIVPshOjmwXBY1CHckhMylhZrkuLz+7DDfhK9dQbgcmHc8C8VruiWhLJmdx
 lP+pkGVY0U7w6vwH0+FQKzMJnsrCfdweK1MXrp6j/mSB0u8YigyQ91eaFu68XZYr
 MaPAJYAPvrBwK4AzW/hzYNeFkJmAHTAb8BCz5MfjVDjnWOR97+IF1RWd+OFUSdnC
 r0m40N1e6L9AybQROoM23dEVmAH+gwObbR+np718tn5/HyDthisfjgGPJG2F7Sik
 GXUWbv5fu0371e1GIXYPXsrkyZ8+psLVnSFqp+I77RbVlLh4qaSBd75cQA21s/Md
 vmWL+byIE9GU2PHjoVxV49j24ULYjahSmewxwT8n2sMLOWKmqHVYAFJc06HP7Udc
 pVqGewMv4eYZgNuUbclEWwdXof6qJ35uksM4C5Ps4oLQood8MSINBDzQkIed4Ylx
 rrCgB9J5+tlQbxTZkvhpxrpXEoEbfT+X57cv9oBTnEyMZ4hknzVSx2+pri8LWWhe
 hWyZ9yJDZobRfxJy9bD0
 =FMeO
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/armbru/tags/pull-error-2015-11-11' into staging

error: More error_setg() usage

# gpg: Signature made Wed 11 Nov 2015 17:57:15 GMT using RSA key ID EB918653
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>"
# gpg:                 aka "Markus Armbruster <armbru@pond.sub.org>"

* remotes/armbru/tags/pull-error-2015-11-11:
  error: More error_setg() usage

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2015-11-12 10:09:14 +00:00
commit c459343b85
6 changed files with 21 additions and 30 deletions

View File

@ -1801,8 +1801,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
ret = bdrv_flush(reopen_state->bs);
if (ret) {
error_set(errp, ERROR_CLASS_GENERIC_ERROR, "Error (%s) flushing drive",
strerror(-ret));
error_setg_errno(errp, -ret, "Error flushing drive");
goto error;
}

View File

@ -210,7 +210,7 @@ if you don't see these strings, then something went wrong.
=== Errors ===
QMP commands should use the error interface exported by the error.h header
file. Basically, errors are set by calling the error_set() function.
file. Basically, most errors are set by calling the error_setg() function.
Let's say we don't accept the string "message" to contain the word "love". If
it does contain it, we want the "hello-world" command to return an error:
@ -219,8 +219,7 @@ void qmp_hello_world(bool has_message, const char *message, Error **errp)
{
if (has_message) {
if (strstr(message, "love")) {
error_set(errp, ERROR_CLASS_GENERIC_ERROR,
"the word 'love' is not allowed");
error_setg(errp, "the word 'love' is not allowed");
return;
}
printf("%s\n", message);
@ -229,10 +228,8 @@ void qmp_hello_world(bool has_message, const char *message, Error **errp)
}
}
The first argument to the error_set() function is the Error pointer to pointer,
which is passed to all QMP functions. The second argument is a ErrorClass
value, which should be ERROR_CLASS_GENERIC_ERROR most of the time (more
details about error classes are given below). The third argument is a human
The first argument to the error_setg() function is the Error pointer
to pointer, which is passed to all QMP functions. The next argument is a human
description of the error, this is a free-form printf-like string.
Let's test the example above. Build qemu, run it as defined in the "Testing"
@ -249,8 +246,9 @@ The QMP server's response should be:
}
}
As a general rule, all QMP errors should use ERROR_CLASS_GENERIC_ERROR. There
are two exceptions to this rule:
As a general rule, all QMP errors should use ERROR_CLASS_GENERIC_ERROR
(done by default when using error_setg()). There are two exceptions to
this rule:
1. A non-generic ErrorClass value exists* for the failure you want to report
(eg. DeviceNotFound)
@ -259,8 +257,8 @@ are two exceptions to this rule:
want to report, hence you have to add a new ErrorClass value so that they
can check for it
If the failure you want to report doesn't fall in one of the two cases above,
just report ERROR_CLASS_GENERIC_ERROR.
If the failure you want to report falls into one of the two cases above,
use error_set() with a second argument of an ErrorClass value.
* All existing ErrorClass values are defined in the qapi-schema.json file

View File

@ -1795,9 +1795,9 @@ static void pc_machine_set_max_ram_below_4g(Object *obj, Visitor *v,
return;
}
if (value > (1ULL << 32)) {
error_set(&error, ERROR_CLASS_GENERIC_ERROR,
"Machine option 'max-ram-below-4g=%"PRIu64
"' expects size less than or equal to 4G", value);
error_setg(&error,
"Machine option 'max-ram-below-4g=%"PRIu64
"' expects size less than or equal to 4G", value);
error_propagate(errp, error);
return;
}

View File

@ -101,8 +101,7 @@ RockerSwitch *qmp_query_rocker(const char *name, Error **errp)
r = rocker_find(name);
if (!r) {
error_set(errp, ERROR_CLASS_GENERIC_ERROR,
"rocker %s not found", name);
error_setg(errp, "rocker %s not found", name);
return NULL;
}
@ -122,8 +121,7 @@ RockerPortList *qmp_query_rocker_ports(const char *name, Error **errp)
r = rocker_find(name);
if (!r) {
error_set(errp, ERROR_CLASS_GENERIC_ERROR,
"rocker %s not found", name);
error_setg(errp, "rocker %s not found", name);
return NULL;
}

View File

@ -2462,15 +2462,13 @@ RockerOfDpaFlowList *qmp_query_rocker_of_dpa_flows(const char *name,
r = rocker_find(name);
if (!r) {
error_set(errp, ERROR_CLASS_GENERIC_ERROR,
"rocker %s not found", name);
error_setg(errp, "rocker %s not found", name);
return NULL;
}
w = rocker_get_world(r, ROCKER_WORLD_TYPE_OF_DPA);
if (!w) {
error_set(errp, ERROR_CLASS_GENERIC_ERROR,
"rocker %s doesn't have OF-DPA world", name);
error_setg(errp, "rocker %s doesn't have OF-DPA world", name);
return NULL;
}
@ -2597,15 +2595,13 @@ RockerOfDpaGroupList *qmp_query_rocker_of_dpa_groups(const char *name,
r = rocker_find(name);
if (!r) {
error_set(errp, ERROR_CLASS_GENERIC_ERROR,
"rocker %s not found", name);
error_setg(errp, "rocker %s not found", name);
return NULL;
}
w = rocker_get_world(r, ROCKER_WORLD_TYPE_OF_DPA);
if (!w) {
error_set(errp, ERROR_CLASS_GENERIC_ERROR,
"rocker %s doesn't have OF-DPA world", name);
error_setg(errp, "rocker %s doesn't have OF-DPA world", name);
return NULL;
}

View File

@ -1330,8 +1330,8 @@ static Object *object_resolve_link(Object *obj, const char *name,
target = object_resolve_path_type(path, target_type, &ambiguous);
if (ambiguous) {
error_set(errp, ERROR_CLASS_GENERIC_ERROR,
"Path '%s' does not uniquely identify an object", path);
error_setg(errp, "Path '%s' does not uniquely identify an object",
path);
} else if (!target) {
target = object_resolve_path(path, &ambiguous);
if (target || ambiguous) {