From e1db398049adf8ea37cebfc8f816be12f9ba131c Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 9 Sep 2016 01:13:23 +0200 Subject: *: centralize error handling --- src/common/error.c | 29 +++++++++++++++++++++++++++++ src/common/error.h | 13 ++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) (limited to 'src/common') diff --git a/src/common/error.c b/src/common/error.c index dbc1d81..78cdc86 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -101,6 +101,35 @@ bc_error_parser(int type, const char *src, size_t src_len, } +// error handling is centralized here for the sake of simplicity :/ +void +bc_error_print(bc_error_t *err) +{ + if (err == NULL) + return; + + switch(err->type) { + case BLOGC_ERROR_SOURCE_PARSER: + fprintf(stderr, "blogc: error: source: %s\n", err->msg); + break; + case BLOGC_ERROR_TEMPLATE_PARSER: + fprintf(stderr, "blogc: error: template: %s\n", err->msg); + break; + case BLOGC_ERROR_LOADER: + fprintf(stderr, "blogc: error: loader: %s\n", err->msg); + break; + case BLOGC_ERROR_FILE: + fprintf(stderr, "blogc: error: file: %s\n", err->msg); + break; + case BLOGC_WARNING_DATETIME_PARSER: + fprintf(stderr, "blogc: warning: datetime: %s\n", err->msg); + break; + default: + fprintf(stderr, "blogc: error: %s\n", err->msg); + } +} + + void bc_error_free(bc_error_t *err) { diff --git a/src/common/error.h b/src/common/error.h index 17843ed..f2845df 100644 --- a/src/common/error.h +++ b/src/common/error.h @@ -11,9 +11,20 @@ #include +// error handling is centralized here for the sake of simplicity :/ +typedef enum { + + // errors for src/blogc + BLOGC_ERROR_SOURCE_PARSER = 100, + BLOGC_ERROR_TEMPLATE_PARSER, + BLOGC_ERROR_LOADER, + BLOGC_ERROR_FILE, + BLOGC_WARNING_DATETIME_PARSER, +} bc_error_type_t; + typedef struct { char *msg; - int type; + bc_error_type_t type; } bc_error_t; bc_error_t* bc_error_new(int type, const char *msg); -- cgit v1.2.3-18-g5258