From 69b157a346b73e0d447f2aebfb3ddb6f3c159d40 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 31 Oct 2020 09:43:52 +0200 Subject: [PATCH] lib: improve error handling, cleanups --- lib/mu-msg.c | 10 ++++++++-- lib/mu-query.cc | 3 --- lib/utils/mu-error.hh | 3 +-- lib/utils/mu-readline.hh | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/mu-msg.c b/lib/mu-msg.c index 240b4516..7dbe45f5 100644 --- a/lib/mu-msg.c +++ b/lib/mu-msg.c @@ -305,13 +305,19 @@ get_num_field (MuMsg *self, MuMsgFieldId mfid) const char* mu_msg_get_header (MuMsg *self, const char *header) { + GError *err; + g_return_val_if_fail (self, NULL); g_return_val_if_fail (header, NULL); /* if we don't have a file object yet, we need to * create it from the file on disk */ - if (!mu_msg_load_msg_file (self, NULL)) - return NULL; + err = NULL; + if (!mu_msg_load_msg_file (self, &err)) { + g_warning ("failed to load message file: %s", + err ? err->message : "something went wrong"); + return NULL; + } return free_later_str (self, mu_msg_file_get_header (self->_file, header)); diff --git a/lib/mu-query.cc b/lib/mu-query.cc index 565d2d49..7719f8e7 100644 --- a/lib/mu-query.cc +++ b/lib/mu-query.cc @@ -482,9 +482,6 @@ mu_query_count_run (MuQuery *self, const char *searchexpr) try } MU_XAPIAN_CATCH_BLOCK_RETURN (0); - - - char* mu_query_internal_xapian (MuQuery *self, const char *searchexpr, GError **err) { diff --git a/lib/utils/mu-error.hh b/lib/utils/mu-error.hh index b2d6ed24..f9119776 100644 --- a/lib/utils/mu-error.hh +++ b/lib/utils/mu-error.hh @@ -30,7 +30,7 @@ namespace Mu { struct Error final: public std::exception { enum struct Code { - AccessDenied, + AccessDenied = 100, // don't overlap with MuError Command, File, Index, @@ -127,7 +127,6 @@ struct Error final: public std::exception { private: const Code code_; std::string what_; - }; diff --git a/lib/utils/mu-readline.hh b/lib/utils/mu-readline.hh index f892f289..c30f84ae 100644 --- a/lib/utils/mu-readline.hh +++ b/lib/utils/mu-readline.hh @@ -21,7 +21,7 @@ namespace Mu { /** - * Setup readline when available & on tty. + * Setup readline when available and on tty. * * @param histpath path to the history file * @param max_lines maximum number of history to save