diff --git a/include/qapi/error.h b/include/qapi/error.h index d712089f1a..f44c451830 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -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 diff --git a/util/error.c b/util/error.c index 2ace0d8dd9..1ff6ae538b 100644 --- a/util/error.c +++ b/util/error.c @@ -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) {