Slightly better error codes



This patch allows TnyAccountStore::alert_func to get some more exact
error codes so that the application doesn't have to just show the
internal error text to the user. It doesn't handle everything, but it's
a start.

-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com
Index: libtinymail-camel/tny-camel-account-priv.h
===================================================================
--- libtinymail-camel/tny-camel-account-priv.h	(revision 2410)
+++ libtinymail-camel/tny-camel-account-priv.h	(working copy)
@@ -79,6 +79,7 @@
 void _tny_camel_account_clear_hooks (TnyCamelAccount *self);
 void _tny_camel_account_refresh (TnyCamelAccount *self, gboolean recon_if);
 void _tny_camel_account_set_online (TnyCamelAccount *self, gboolean online, GError **err);
+TnyError _tny_camel_account_get_tny_error_code_for_camel_exception_id (CamelException* ex);
 
 
 #define TNY_CAMEL_ACCOUNT_GET_PRIVATE(o)	\
Index: libtinymail-camel/camel-lite/camel/camel-net-utils.c
===================================================================
--- libtinymail-camel/camel-lite/camel/camel-net-utils.c	(revision 2410)
+++ libtinymail-camel/camel-lite/camel/camel-net-utils.c	(working copy)
@@ -716,9 +716,10 @@
 	msg->hostbufmem = g_malloc(msg->hostbuflen);
 #endif	
 	if (cs_waitinfo(cs_getaddrinfo, msg, _("Host lookup failed"), ex) == 0) {
-		if (msg->result != 0)
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Host lookup failed: %s: %s"),
+		if (msg->result != 0) {
+			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM_HOST_LOOKUP_FAILED, _("Host lookup failed: %s: %s"),
 					      name, gai_strerror (msg->result));
+		}
 		
 		cs_freeinfo(msg);
 	} else
Index: libtinymail-camel/camel-lite/camel/camel-exception-list.def
===================================================================
--- libtinymail-camel/camel-lite/camel/camel-exception-list.def	(revision 2410)
+++ libtinymail-camel/camel-lite/camel/camel-exception-list.def	(working copy)
@@ -10,6 +10,7 @@
 /* Generic exceptions */
 CAMEL_EXCEPTION_INVALID_PARAM,
 CAMEL_EXCEPTION_SYSTEM,
+CAMEL_EXCEPTION_SYSTEM_HOST_LOOKUP_FAILED,
 CAMEL_EXCEPTION_USER_CANCEL,
 
 /* CamelFolderException */
Index: libtinymail-camel/tny-session-camel.c
===================================================================
--- libtinymail-camel/tny-session-camel.c	(revision 2410)
+++ libtinymail-camel/tny-session-camel.c	(working copy)
@@ -179,7 +179,7 @@
    camel_session_get_service is issued (for example TnyCamelTransportAccount and
    TnyCamelStore account issue this function). Its implementation is often done
    with GUI components (it should therefore not be called from a thread). This
-   is a known issue (and the person who fixed this, please remove this warning) */
+   is a known issue (and if someone fixes this, please remove this warning) */
 
 static gboolean
 tny_session_camel_alert_user (CamelSession *session, CamelSessionAlertType type, const char *msg, gboolean cancel)
@@ -207,12 +207,15 @@
 			break;
 		}
 
+		/* TODO: A string comparison is not a very safe way to do this: */
 		if (strstr (msg, "Canceled") != NULL)
 			g_set_error (&err, TNY_ACCOUNT_STORE_ERROR, 
 				TNY_ACCOUNT_STORE_ERROR_CANCEL_ALERT, "The connecting got canceled");
-		else
+		else {
+			/* TODO: Use a more specific error code, based on a CamelException ID: */
 			g_set_error (&err, TNY_ACCOUNT_STORE_ERROR, 
 				TNY_ACCOUNT_STORE_ERROR_UNKNOWN_ALERT, msg);
+		}
 
 		tny_lockable_lock (self->priv->ui_lock);
 
Index: libtinymail-camel/tny-camel-account.c
===================================================================
--- libtinymail-camel/tny-camel-account.c	(revision 2410)
+++ libtinymail-camel/tny-camel-account.c	(working copy)
@@ -146,9 +146,9 @@
 		camel_service_disconnect (apriv->service, FALSE, &ex);
 		if (camel_exception_is_set (&ex))
 			camel_exception_clear (&ex);
+
 		camel_service_connect (apriv->service, &ex);
 
-
 		if (apriv->service->reconnection)
 		{
 			if (!camel_exception_is_set (&ex))
@@ -313,6 +313,36 @@
 	return;
 }
 
+TnyError
+_tny_camel_account_get_tny_error_code_for_camel_exception_id (CamelException* ex)
+{
+	printf ("DEBUG: %s: ex->id=%d, ex->desc=%s\n", __FUNCTION__, ex->id, ex->desc);
+	if (!ex) {
+		g_warning ("%s: The exception was NULL.\n", __FUNCTION__);
+		return TNY_ACCOUNT_ERROR_TRY_CONNECT;
+	}
+
+
+	/* Try to provide a precise error code, 
+	 * as much as possible: 
+	 */
+	switch (ex->id) {
+	case CAMEL_EXCEPTION_SYSTEM_HOST_LOOKUP_FAILED:
+		return TNY_ACCOUNT_ERROR_TRY_CONNECT_HOST_LOOKUP_FAILED;
+	case CAMEL_EXCEPTION_SERVICE_UNAVAILABLE:
+		return TNY_ACCOUNT_ERROR_TRY_CONNECT_SERVICE_UNAVAILABLE;
+	case CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE:
+		return TNY_ACCOUNT_ERROR_TRY_CONNECT_AUTHENTICATION_NOT_SUPPORTED;
+	case CAMEL_EXCEPTION_SYSTEM:
+	default:
+		/* A generic exception. 
+		 * We should always try to provide a precise error code rather than this,
+		 * so we can show a more helpful (translated) error message to the user.
+		 */
+		return TNY_ACCOUNT_ERROR_TRY_CONNECT;
+	}
+}
+
 void 
 _tny_camel_account_try_connect (TnyCamelAccount *self, gboolean for_online, GError **err)
 {
@@ -323,8 +353,9 @@
 	if (camel_exception_is_set (priv->ex))
 	{
 		g_set_error (err, TNY_ACCOUNT_ERROR, 
-			TNY_ACCOUNT_ERROR_TRY_CONNECT,
+			_tny_camel_account_get_tny_error_code_for_camel_exception_id (priv->ex),
 			camel_exception_get_description (priv->ex));
+		printf ("DEBUG: %s: camel exception: message=%s\n", __FUNCTION__, (*err)->message);
 	}
 
 	return;
@@ -1128,7 +1159,7 @@
 		if (camel_exception_is_set (priv->ex))
 		{
 			g_set_error (err, TNY_ACCOUNT_ERROR, 
-				TNY_ACCOUNT_ERROR_TRY_CONNECT,
+				_tny_camel_account_get_tny_error_code_for_camel_exception_id (priv->ex),
 				camel_exception_get_description (priv->ex));
 		} else {
 			g_set_error (err, TNY_ACCOUNT_ERROR, 
@@ -1246,7 +1277,7 @@
 	if (camel_exception_is_set (&ex))
 	{
 		g_set_error (err, TNY_ACCOUNT_ERROR, 
-			TNY_ACCOUNT_ERROR_TRY_CONNECT,
+			_tny_camel_account_get_tny_error_code_for_camel_exception_id (&ex),
 			camel_exception_get_description (&ex));
 	}
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 2410)
+++ ChangeLog	(working copy)
@@ -1,3 +1,30 @@
+2007-07-06  Murray Cumming  <murrayc murrayc com>
+
+	* libtinymail/tny-enums.h:
+	* libtinymail/tny-error.h: Added 
+	TNY_ACCOUNT_ERROR_TRY_CONNECT_HOST_LOOKUP_FAILED, 
+	TNY_ACCOUNT_ERROR_TRY_CONNECT_SERVICE_UNAVAILABLE and 
+	TNY_ACCOUNT_ERROR_TRY_CONNECT_AUTHENTICATION_NOT_SUPPORTED so 
+	that the TnyAccountStore::alert_func() callback can sometimes get 
+	more specific information, so that it doesn't need to just blindly show 
+	the camel internal error message.
+	* libtinymail-camel/tny-camel-account-priv.h:
+	* libtinymail-camel/tny-camel-account.c:
+	Added _tny_camel_account_get_tny_error_code_for_camel_exception_id() for 
+	choosing a suitable tinymail GError code.
+	(_tny_camel_account_try_connect), (_tny_camel_account_set_online):
+	Use a specific error code for the GErrors.
+
+	* libtinymail-camel/tny-session-camel.c:
+	(tny_session_camel_alert_user): Add a TODO noting that this is where we 
+	lose some specific error codes, and where we do a dodgy string comparison 
+	on the message text.
+
+	* camel/camel-exception-list.def: Added a 
+	CAMEL_EXCEPTION_SYSTEM_HOST_LOOKUP_FAILED error code enum value.
+	* camel/camel-net-utils.c: (camel_getaddrinfo):
+	Use the new error code when appropriate.
+
 2007-07-06  Philip Van Hoof  <pvanhoof gnome org>
 
 	* Added some non standard flags to the maildir support
Index: libtinymail/tny-enums.h
===================================================================
--- libtinymail/tny-enums.h	(revision 2410)
+++ libtinymail/tny-enums.h	(working copy)
@@ -75,6 +75,9 @@
 	TNY_TRANSPORT_ACCOUNT_ERROR_SEND = 13,
 
 	TNY_ACCOUNT_ERROR_TRY_CONNECT = 14,
+	TNY_ACCOUNT_ERROR_TRY_CONNECT_HOST_LOOKUP_FAILED = 19,
+	TNY_ACCOUNT_ERROR_TRY_CONNECT_SERVICE_UNAVAILABLE = 20,
+	TNY_ACCOUNT_ERROR_TRY_CONNECT_AUTHENTICATION_NOT_SUPPORTED = 21,
 
 	TNY_ACCOUNT_STORE_ERROR_UNKNOWN_ALERT = 15,
 
@@ -83,6 +86,8 @@
 	TNY_SEND_QUEUE_ERROR_ADD = 17,
 
 	TNY_ACCOUNT_STORE_ERROR_CANCEL_ALERT = 18,
+
+
 } TnyError;
 
 typedef enum  {
Index: libtinymail/tny-error.h
===================================================================
--- libtinymail/tny-error.h	(revision 2410)
+++ libtinymail/tny-error.h	(working copy)
@@ -94,6 +94,9 @@
 	TNY_TRANSPORT_ACCOUNT_ERROR_SEND = 13,
 
 	TNY_ACCOUNT_ERROR_TRY_CONNECT = 14,
+	TNY_ACCOUNT_ERROR_TRY_CONNECT_HOST_LOOKUP_FAILED = 19,
+	TNY_ACCOUNT_ERROR_TRY_CONNECT_SERVICE_UNAVAILABLE = 20,
+	TNY_ACCOUNT_ERROR_TRY_CONNECT_AUTHENTICATION_NOT_SUPPORTED = 21,
 
 	TNY_ACCOUNT_STORE_ERROR_UNKNOWN_ALERT = 15,
 


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