error: New convenience function error_report_err()
authorMarkus Armbruster <armbru@redhat.com>
Fri, 6 Feb 2015 14:27:19 +0000 (15:27 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Wed, 18 Feb 2015 09:50:43 +0000 (10:50 +0100)
I've typed error_report("%s", error_get_pretty(ERR)) too many times
already, and I've fixed too many instances of qerror_report_err(ERR)
to error_report("%s", error_get_pretty(ERR)) as well.  Capture the
pattern in a convenience function.

Since it's almost invariably followed by error_free(), stuff that into
the convenience function as well.

The next patch will put it to use.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
include/qapi/error.h
util/error.c

index d712089f1ae1585e145e7c26755802bd0fe8302d..f44c451830d4fe78e9419c8530d23dea6411f22a 100644 (file)
@@ -82,6 +82,11 @@ Error *error_copy(const Error *err);
  */
 const char *error_get_pretty(Error *err);
 
+/**
+ * Convenience function to error_report() and free an error object.
+ */
+void error_report_err(Error *);
+
 /**
  * Propagate an error to an indirect pointer to an error.  This function will
  * always transfer ownership of the error reference and handles the case where
index 2ace0d8dd95bb0df878bf05871151ac3e35dc374..1ff6ae538b328edf1196100afa9dc1825eeaf6de 100644 (file)
@@ -152,6 +152,12 @@ const char *error_get_pretty(Error *err)
     return err->msg;
 }
 
+void error_report_err(Error *err)
+{
+    error_report("%s", error_get_pretty(err));
+    error_free(err);
+}
+
 void error_free(Error *err)
 {
     if (err) {