block: Fix block-set-write-threshold not to use funky error class
PATCH 1/1 block: Fix block-set-write-threshold not to use funky error class
Error classes are a leftover from the days of "rich" error objects. New code should always use ERROR_CLASS_GENERIC_ERROR. Commit e246211 added a use of ERROR_CLASS_DEVICE_NOT_FOUND. Replace it.
--- block/write-threshold.c | 2 +- qapi/block-core.json | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-)
block/write-threshold.c +1 -1
@@ -112,7 +112,7 @@ void qmp_block_set_write_threshold(const char *node_name, bs =bdrv_find_node (node_name);if (!bs) { -error_set (errp,QERR_DEVICE_NOT_FOUND , node_name); +error_setg (errp,"Device '%s' not found" , node_name);return ; }
qapi/block-core.json +0 -4
@@ -1961,10 +1961,6 @@ # @write-threshold: configured threshold for the block device, bytes. # Use 0 to disable the threshold. # -# Returns: Nothing on success -# If @node name is not found on the block device graph, -# DeviceNotFound -# # Since: 2.3 ## { 'command': 'block-set-write-threshold',
Signature · 1 line
1.9.3
Quoted 2 lines · Markus Armbruster
Error classes are a leftover from the days of "rich" error objects. New code should always use
ERROR_CLASS_GENERIC_ERROR.
More precisely, new code should use ERROR_CLASS_GENERIC_ERROR unless there is a good reason where a caller knowing a different error class is likely to react differently as a result (for example, with 'drive-mirror', libvirt DOES rely on QERR_DEVICE_NOT_FOUND as a witness that the command supports an optional 'top' argument, vs. ERROR_CLASS_GENERIC_ERROR to state that 'top' was still mandatory).
But I agree that this situation is one unlikely to be where libvirt cares what error class was used.
Quoted 8 lines
Commit e246211
added a use ofERROR_CLASS_DEVICE_NOT_FOUND. Replace it.Signed-off-by Markus Armbruster <[email protected]>--- block/write-threshold.c | 2 +- qapi/block-core.json | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 10 lines · Eric Blake
Quoted 2 lines · Markus Armbruster
Error classes are a leftover from the days of "rich" error objects. New code should always use
ERROR_CLASS_GENERIC_ERROR.More precisely, new code should use
ERROR_CLASS_GENERIC_ERRORunless there is a good reason where a caller knowing a different error class is likely to react differently as a result (for example, with 'drive-mirror', libvirt DOES rely onQERR_DEVICE_NOT_FOUNDas a witness that the command supports an optional 'top' argument, vs.ERROR_CLASS_GENERIC_ERRORto state that 'top' was still mandatory).
In my experience, a caller / client wanting to figure out what exactly failed is often a sign of a function / command trying to do too much at once.
Using error classes to introspect is trickery, committed out of desperation. We should offer proper introspection instead.
That said, "always" is rather strong language. No rule without exceptions. If it bothers you, perhaps the word can be dropped on commit.
Quoted 6 lines
But I agree that this situation is one unlikely to be where libvirt cares what error class was used.
Quoted 3 lines
Commit e246211
added a use ofERROR_CLASS_DEVICE_NOT_FOUND. Replace it.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Markus Armbruster <[email protected]>--- block/write-threshold.c | 2 +- qapi/block-core.json | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-)Reviewed-by Eric Blake <[email protected]>
Thanks!
Kevin Wolf
AppliedAm 13.03.2015 um 18:51 hat Markus Armbruster geschrieben:
Quoted 5 lines
Error classes are a leftover from the days of "rich" error objects. New code should always use
ERROR_CLASS_GENERIC_ERROR. Commit e246211 added a use ofERROR_CLASS_DEVICE_NOT_FOUND. Replace it.Signed-off-by Markus Armbruster <[email protected]>
Thanks, applied to the block branch.
Kevin