Re: [Qemu-block] [PATCH 1/3] error: add error_get_hint
On 11/2/18 10:11 AM, Vladimir Sementsov-Ogievskiy wrote: Add a function to export error hint - a pair to error_get_pretty. It's needed to handle errors by hand, where we can't just report it or propagate. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/qapi/error.h | 5 + util/error.c | 5 + 2 files changed, 10 insertions(+) I'll have to see how this is used before agreeing to it, but the code itself is fine if the series does indeed warrant it. I wouldn't mind Markus chiming in on the topic, either. Reviewed-by: Eric Blake +const char *error_get_hint(const Error *err) +{ +return err->hint ? err->hint->str : NULL; +} + void error_report_err(Error *err) { error_report("%s", error_get_pretty(err)); -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
[Qemu-block] [PATCH 1/3] error: add error_get_hint
Add a function to export error hint - a pair to error_get_pretty. It's needed to handle errors by hand, where we can't just report it or propagate. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/qapi/error.h | 5 + util/error.c | 5 + 2 files changed, 10 insertions(+) diff --git a/include/qapi/error.h b/include/qapi/error.h index 51b63dd4b5..ff2f61b877 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -139,6 +139,11 @@ typedef enum ErrorClass { */ const char *error_get_pretty(const Error *err); +/* + * Get @err's hint if any. Otherwise return NULL. + */ +const char *error_get_hint(const Error *err); + /* * Get @err's error class. * Note: use of error classes other than ERROR_CLASS_GENERIC_ERROR is diff --git a/util/error.c b/util/error.c index b5ccbd8eac..e7cedd5c4a 100644 --- a/util/error.c +++ b/util/error.c @@ -223,6 +223,11 @@ const char *error_get_pretty(const Error *err) return err->msg; } +const char *error_get_hint(const Error *err) +{ +return err->hint ? err->hint->str : NULL; +} + void error_report_err(Error *err) { error_report("%s", error_get_pretty(err)); -- 2.18.0