diff mbox

[v2,01/17] error: introduce handle_error

Message ID bd0762ea29f3959c9a25092a531642c4f9fcfd9f.1355404685.git.phrdina@redhat.com
State New
Headers show

Commit Message

Pavel Hrdina Dec. 13, 2012, 3:40 p.m. UTC
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 error.c | 8 ++++++++
 error.h | 6 ++++++
 2 files changed, 14 insertions(+)

Comments

Eric Blake Dec. 14, 2012, 12:52 a.m. UTC | #1
On 12/13/2012 08:40 AM, Pavel Hrdina wrote:
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  error.c | 8 ++++++++
>  error.h | 6 ++++++
>  2 files changed, 14 insertions(+)
> 

>  
> +/**
> + * Print an error object as pretty string to current monitor or on stderr, then
> + * free the errot object.

s/errot/error/
Luiz Capitulino Dec. 14, 2012, 4 p.m. UTC | #2
On Thu, 13 Dec 2012 16:40:35 +0100
Pavel Hrdina <phrdina@redhat.com> wrote:

> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  error.c | 8 ++++++++
>  error.h | 6 ++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/error.c b/error.c
> index 128d88c..dd3ab66 100644
> --- a/error.c
> +++ b/error.c
> @@ -113,3 +113,11 @@ void error_propagate(Error **dst_err, Error *local_err)
>          error_free(local_err);
>      }
>  }
> +
> +void handle_error(Error **errp)
> +{
> +    if (error_is_set(errp)) {
> +        error_report("%s", error_get_pretty(*errp));
> +        error_free(*errp);
> +    }

This is not good for a few reasons. The most important ones are that
we most probably shouldn't be using error_report() in new qapi code. The
other reason is that this function doesn't actually handle the error.

I've added a similar function in hmp.c but just to save some typing,
but we shouldn't do this elsewhere.

> +}
> diff --git a/error.h b/error.h
> index 4d52e73..6a6acb5 100644
> --- a/error.h
> +++ b/error.h
> @@ -77,4 +77,10 @@ void error_propagate(Error **dst_err, Error *local_err);
>   */
>  void error_free(Error *err);
>  
> +/**
> + * Print an error object as pretty string to current monitor or on stderr, then
> + * free the errot object.
> + */
> +void handle_error(Error **errp);
> +
>  #endif
diff mbox

Patch

diff --git a/error.c b/error.c
index 128d88c..dd3ab66 100644
--- a/error.c
+++ b/error.c
@@ -113,3 +113,11 @@  void error_propagate(Error **dst_err, Error *local_err)
         error_free(local_err);
     }
 }
+
+void handle_error(Error **errp)
+{
+    if (error_is_set(errp)) {
+        error_report("%s", error_get_pretty(*errp));
+        error_free(*errp);
+    }
+}
diff --git a/error.h b/error.h
index 4d52e73..6a6acb5 100644
--- a/error.h
+++ b/error.h
@@ -77,4 +77,10 @@  void error_propagate(Error **dst_err, Error *local_err);
  */
 void error_free(Error *err);
 
+/**
+ * Print an error object as pretty string to current monitor or on stderr, then
+ * free the errot object.
+ */
+void handle_error(Error **errp);
+
 #endif