Re: Slightly better error codes
- From: Murray Cumming <murrayc murrayc com>
- To: Philip Van Hoof <spam pvanhoof be>
- Cc: tinymail-devel-list <tinymail-devel-list gnome org>
- Subject: Re: Slightly better error codes
- Date: Mon, 09 Jul 2007 11:29:25 +0200
On Fri, 2007-07-06 at 22:40 +0200, Philip Van Hoof wrote:
> Approval to commit
>
> On Fri, 2007-07-06 at 19:57 +0200, Murray Cumming wrote:
> > On Fri, 2007-07-06 at 15:47 +0200, Philip Van Hoof wrote:
> > > *. Please update tny-enums.h too, else gtk-doc wont show the new enums
> > >
> > > *. There are GType's for the enums that also need to be updated, else
> > > (future) bindings wont recognise those enums: tny_error_get_type in
> > > tny-error.c
> > >
> > >
> > > On Fri, 2007-07-06 at 15:29 +0200, Murray Cumming wrote:
> > > > 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.
> >
> > Here is another one. It still doesn't provider meaningful error codes
> > for everything, but this makes it much easier to add them when we find
> > we really need them later.
And here is a similar patch for the TnySendQueue:
--
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com
Index: libtinymail-camel/tny-camel-transport-account.c
===================================================================
--- libtinymail-camel/tny-camel-transport-account.c (revision 2427)
+++ libtinymail-camel/tny-camel-transport-account.c (working copy)
@@ -118,7 +118,7 @@
if (camel_exception_is_set (apriv->ex))
{
g_set_error (err, TNY_ACCOUNT_ERROR,
- TNY_ACCOUNT_ERROR_TRY_CONNECT,
+ _tny_camel_account_get_tny_error_code_for_camel_exception_id (apriv->ex),
camel_exception_get_description (apriv->ex));
camel_exception_clear (apriv->ex);
} else {
@@ -154,6 +154,37 @@
}
+/** Get an appropriate Tinymail GError code for a CamelException.
+ */
+static TnyError
+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_TRANSPORT_ACCOUNT_ERROR_SEND;
+ }
+
+ /* Try to provide a precise error code,
+ * as much as possible:
+ */
+ switch (ex->id) {
+ case CAMEL_EXCEPTION_SYSTEM_HOST_LOOKUP_FAILED:
+ return TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED;
+ case CAMEL_EXCEPTION_SERVICE_UNAVAILABLE:
+ return TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE;
+ case CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE:
+ return TNY_TRANSPORT_ACCOUNT_ERROR_SEND_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_TRANSPORT_ACCOUNT_ERROR_SEND;
+ }
+}
+
static void
tny_camel_transport_account_send_default (TnyTransportAccount *self, TnyMsg *msg, GError **err)
{
@@ -170,7 +201,7 @@
if (apriv->service == NULL || !CAMEL_IS_SERVICE (apriv->service))
{
g_set_error (err, TNY_TRANSPORT_ACCOUNT_ERROR,
- TNY_TRANSPORT_ACCOUNT_ERROR_SEND,
+ get_tny_error_code_for_camel_exception_id (apriv->ex),
"Account not ready for this operation (%s). "
"This problem indicates a bug in the software.",
camel_exception_get_description (apriv->ex));
@@ -190,7 +221,7 @@
if (camel_exception_is_set (&ex))
{
g_set_error (err, TNY_TRANSPORT_ACCOUNT_ERROR,
- TNY_TRANSPORT_ACCOUNT_ERROR_SEND,
+ get_tny_error_code_for_camel_exception_id (&ex),
camel_exception_get_description (&ex));
g_static_rec_mutex_unlock (apriv->service_lock);
return;
@@ -211,7 +242,7 @@
if (camel_exception_is_set (&ex))
{
g_set_error (err, TNY_TRANSPORT_ACCOUNT_ERROR,
- TNY_TRANSPORT_ACCOUNT_ERROR_SEND,
+ get_tny_error_code_for_camel_exception_id (&ex),
camel_exception_get_description (&ex));
camel_exception_clear (&ex);
} else
@@ -227,7 +258,7 @@
if (reperr && camel_exception_is_set (&ex))
{
g_set_error (err, TNY_TRANSPORT_ACCOUNT_ERROR,
- TNY_TRANSPORT_ACCOUNT_ERROR_SEND,
+ get_tny_error_code_for_camel_exception_id (&ex),
camel_exception_get_description (&ex));
camel_exception_clear (&ex);
}
Index: ChangeLog
===================================================================
--- ChangeLog (revision 2427)
+++ ChangeLog (working copy)
@@ -1,3 +1,22 @@
+2007-07-09 Murray Cumming <murrayc murrayc com>
+
+ * libtinymail/tny-enums.h:
+ * libtinymail/tny-error.c: (tny_error_get_type):
+ * libtinymail/tny-error.h:
+ Added TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED,
+ TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE,
+ TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED
+ GError enum values.
+
+ * libtinymail-camel/tny-camel-transport-account.c:
+ Added get_tny_error_code_for_camel_exception_id(),
+ (tny_camel_transport_account_send_default): Provide a
+ more specific GError code to the caller, so that this will
+ be provided with the TnySendQueue "error-happened" signal.
+ (tny_camel_transport_account_try_connect):
+ Use _tny_camel_account_get_tny_error_code_for_camel_exception_id()
+ here to provide a more specific error code.
+
2007-07-09 Philip Van Hoof <pvanhoof gnome org>
* Improvement for tny_camel_mime_part_is_attachment_default
Index: libtinymail/tny-error.c
===================================================================
--- libtinymail/tny-error.c (revision 2427)
+++ libtinymail/tny-error.c (working copy)
@@ -77,6 +77,9 @@
{ TNY_FOLDER_STORE_ERROR_CREATE_FOLDER, "TNY_FOLDER_STORE_ERROR_CREATE_FOLDER", "folder_store_error_create_folder" },
{ TNY_TRANSPORT_ACCOUNT_ERROR_SEND, "TNY_TRANSPORT_ACCOUNT_ERROR_SEND", "transport_account_error_send" },
+ { TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED, "TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED", "transport_account_error_send_host_lookup_failed" },
+ { TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE, "TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE", "transport_account_error_send_service_unavailable" },
+ { TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED, "TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED", "transport_account_error_send_authentication_not_supported" },
{ TNY_ACCOUNT_ERROR_TRY_CONNECT, "TNY_ACCOUNT_ERROR_TRY_CONNECT", "account_error_try_connect" },
{ TNY_ACCOUNT_ERROR_TRY_CONNECT_HOST_LOOKUP_FAILED, "TNY_ACCOUNT_ERROR_TRY_CONNECT_HOST_LOOKUP_FAILED", "account_error_try_connect_host_lookup_failed" },
Index: libtinymail/tny-enums.h
===================================================================
--- libtinymail/tny-enums.h (revision 2427)
+++ libtinymail/tny-enums.h (working copy)
@@ -73,6 +73,9 @@
TNY_FOLDER_STORE_ERROR_CREATE_FOLDER = 12,
TNY_TRANSPORT_ACCOUNT_ERROR_SEND = 13,
+ TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED = 23,
+ TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE = 24,
+ TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED = 25,
TNY_ACCOUNT_ERROR_TRY_CONNECT = 14,
TNY_ACCOUNT_ERROR_TRY_CONNECT_HOST_LOOKUP_FAILED = 19,
Index: libtinymail/tny-error.h
===================================================================
--- libtinymail/tny-error.h (revision 2427)
+++ libtinymail/tny-error.h (working copy)
@@ -107,6 +107,9 @@
TNY_FOLDER_STORE_ERROR_CREATE_FOLDER = 12,
TNY_TRANSPORT_ACCOUNT_ERROR_SEND = 13,
+ TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED = 23,
+ TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE = 24,
+ TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED = 25,
TNY_ACCOUNT_ERROR_TRY_CONNECT = 14,
TNY_ACCOUNT_ERROR_TRY_CONNECT_HOST_LOOKUP_FAILED = 19,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]