diff options
author | Carl Worth <cworth@cworth.org> | 2009-10-25 10:22:41 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2009-10-25 10:54:49 -0700 |
commit | 7b227a6bf7eb409b4353adc430b2545166e0c4cd (patch) | |
tree | 9b82d6e3bec4596fdbbec6a7c449e00e3e19ad03 /notmuch.c | |
parent | 3b8e3ab666a54407f9596a53c66ba8ce623ac91d (diff) |
Add an INTERNAL_ERROR macro and use it for all internal errors.
We were previously just doing fprintf;exit at each point, but I
wanted to add file and line-number details to all messages, so it
makes sense to use a single macro for that.
Diffstat (limited to 'notmuch.c')
-rw-r--r-- | notmuch.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -43,6 +43,20 @@ #include <glib.h> /* g_strdup_printf */ +/* There's no point in continuing when we've detected that we've done + * something wrong internally (as opposed to the user passing in a + * bogus value). + * + * Note that __location__ comes from talloc.h. + */ +#define INTERNAL_ERROR(format, ...) \ + do { \ + fprintf(stderr, \ + "Internal error: " format " (%s)\n", \ + ##__VA_ARGS__, __location__); \ + exit (1); \ + } while (0) + #define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0])) typedef int (*command_function_t) (int argc, char *argv[]); @@ -255,8 +269,7 @@ add_files_recursive (notmuch_database_t *notmuch, ret = status; goto DONE; default: - fprintf (stderr, "Internal error: add_message returned unexpected value: %d\n", status); - ret = status; + INTERNAL_ERROR ("add_message returned unexpected value: %d", status); goto DONE; } if (state->processed_files % 1000 == 0) |