diff mbox series

[v6,2/7] qapi/commands: refactor error handling code

Message ID 20220126161130.3240892-3-vsementsov@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series trace qmp commands | expand

Commit Message

Vladimir Sementsov-Ogievskiy Jan. 26, 2022, 4:11 p.m. UTC
Move error_propagate() to if (err) and make "if (err)" block mandatory.
This is to simplify further commit, which will bring trace events
generation for QMP commands.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 docs/devel/qapi-code-gen.rst |  2 +-
 scripts/qapi/commands.py     | 10 +++++++---
 2 files changed, 8 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst
index a3b5473089..feafed79b5 100644
--- a/docs/devel/qapi-code-gen.rst
+++ b/docs/devel/qapi-code-gen.rst
@@ -1690,8 +1690,8 @@  Example::
         }
 
         retval = qmp_my_command(arg.arg1, &err);
-        error_propagate(errp, err);
         if (err) {
+            error_propagate(errp, err);
             goto out;
         }
 
diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index 21001bbd6b..17e5ed2414 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -74,14 +74,18 @@  def gen_call(name: str,
     ret = mcgen('''
 
     %(lhs)sqmp_%(c_name)s(%(args)s&err);
-    error_propagate(errp, err);
 ''',
                 c_name=c_name(name), args=argstr, lhs=lhs)
-    if ret_type:
-        ret += mcgen('''
+
+    ret += mcgen('''
     if (err) {
+        error_propagate(errp, err);
         goto out;
     }
+''')
+
+    if ret_type:
+        ret += mcgen('''
 
     qmp_marshal_output_%(c_name)s(retval, ret, errp);
 ''',