Skip to content

Commit

Permalink
qmp-dispatch: Use CommandNotFound error for disabled commands
Browse files Browse the repository at this point in the history
If a command is disabled an error is reported.  But due to usage of
error_setg() the class of the error is GenericError which does not
help callers in distinguishing this case from a case where a qmp
command fails regularly due to other reasons.

We used to use class CommandDisabled until the great error
simplification (commit de253f1 for QMP and commit 93b91c5 for
qemu-ga, both v1.2.0).

Use CommandNotFound error class, which is close enough.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Message-Id: <faeb030e6a1044f0fd88208edfdb1c5fafe5def9.1567171655.git.mprivozn@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[Test update squashed in, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
  • Loading branch information
zippy2 authored and Markus Armbruster committed Sep 28, 2019
1 parent c6f5012 commit 2546be1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions qapi/qmp-dispatch.c
Expand Up @@ -104,8 +104,9 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, QObject *request,
return NULL;
}
if (!cmd->enabled) {
error_setg(errp, "The command %s has been disabled for this instance",
command);
error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND,
"The command %s has been disabled for this instance",
command);
return NULL;
}
if (oob && !(cmd->options & QCO_ALLOW_OOB)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/test-qga.c
Expand Up @@ -668,7 +668,7 @@ static void test_qga_blacklist(gconstpointer data)
error = qdict_get_qdict(ret, "error");
class = qdict_get_try_str(error, "class");
desc = qdict_get_try_str(error, "desc");
g_assert_cmpstr(class, ==, "GenericError");
g_assert_cmpstr(class, ==, "CommandNotFound");
g_assert_nonnull(g_strstr_len(desc, -1, "has been disabled"));
qobject_unref(ret);

Expand All @@ -677,7 +677,7 @@ static void test_qga_blacklist(gconstpointer data)
error = qdict_get_qdict(ret, "error");
class = qdict_get_try_str(error, "class");
desc = qdict_get_try_str(error, "desc");
g_assert_cmpstr(class, ==, "GenericError");
g_assert_cmpstr(class, ==, "CommandNotFound");
g_assert_nonnull(g_strstr_len(desc, -1, "has been disabled"));
qobject_unref(ret);

Expand Down

0 comments on commit 2546be1

Please sign in to comment.