[evolution-data-server] Disallow overwriting one CamelException with another.



commit 4f99bcad61ebc49ae520414a32372f84605baf6b
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun May 9 10:24:47 2010 -0500

    Disallow overwriting one CamelException with another.
    
    Make CamelException behave more like GError: accept the first error
    and reject subsequent errors with a runtime warning, unless the first
    error is cleared first.
    
    This may expose existing error handling bugs in the Camel providers,
    but that's what we want: fixing these bugs will smooth the transition
    to GError.

 camel/camel-exception.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/camel/camel-exception.c b/camel/camel-exception.c
index 22db7f5..bc91a49 100644
--- a/camel/camel-exception.c
+++ b/camel/camel-exception.c
@@ -36,6 +36,12 @@
 /* dont turn this off */
 #define w(x) x
 
+#define ERROR_OVERWRITTEN_WARNING \
+	"CamelException set over top of a previous CamelException.\n" \
+	"This indicates a bug in someone's code. You must ensure a " \
+	"CamelException is clear before it's set.\n" \
+	"The overwriting error message was: %s"
+
 /**
  * camel_exception_new: allocate a new exception object.
  *
@@ -133,6 +139,12 @@ camel_exception_set (CamelException *ex, ExceptionId id, const gchar *desc)
 		printf("CamelException.set(%p, %u, '%s')\n", (gpointer) ex, id, desc);
 	if (!ex)
 		return;
+
+	if (camel_exception_is_set (ex)) {
+		g_warning (ERROR_OVERWRITTEN_WARNING, desc);
+		return;
+	}
+
 	ex->id = id;
 	if (desc != ex->desc) {
 		g_free (ex->desc);
@@ -178,6 +190,11 @@ camel_exception_setv (CamelException *ex, ExceptionId id, const gchar *format, .
 		return;
 	}
 
+	if (camel_exception_is_set (ex)) {
+		g_warning (ERROR_OVERWRITTEN_WARNING, desc);
+		return;
+	}
+
 	g_free(ex->desc);
 	ex->desc = desc;
 	ex->id = id;
@@ -207,6 +224,11 @@ camel_exception_xfer (CamelException *ex_dst,
 		return;
 	}
 
+	if (camel_exception_is_set (ex_dst)) {
+		g_warning (ERROR_OVERWRITTEN_WARNING, ex_src->desc);
+		return;
+	}
+
 	if (ex_dst->desc)
 		g_free (ex_dst->desc);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]