Skip to contentSkip to conversation

block: Fix block-set-write-threshold not to use funky error class

PATCH Applied Markus Armbruster 3 participants 4 messages Mar 13, 2015 – Mar 16, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

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
index c2cd517..a53c1f5 100644
@@ -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
index 90586a5..42c8850 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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 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(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
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_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).

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 of ERROR_CLASS_DEVICE_NOT_FOUND. Replace it.

Quoted 7 lines
Quoted 5 lines
---
 block/write-threshold.c | 2 +-
 qapi/block-core.json    | 4 ----
 2 files changed, 1 insertion(+), 5 deletions(-)

Thanks!

Applied
#3 lore raw
In reply to Markus Armbruster

Am 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 of ERROR_CLASS_DEVICE_NOT_FOUND. Replace it.

Thanks, applied to the block branch.

Kevin