aboutsummaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-09-09 01:13:23 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-09-09 01:13:23 +0200
commite1db398049adf8ea37cebfc8f816be12f9ba131c (patch)
treeae6efacc5172caf211abe65510c105029ee2e09e /src/common
parentd97662894bab06133830c2936986b7f1e57ae26f (diff)
downloadblogc-e1db398049adf8ea37cebfc8f816be12f9ba131c.tar.gz
blogc-e1db398049adf8ea37cebfc8f816be12f9ba131c.tar.bz2
blogc-e1db398049adf8ea37cebfc8f816be12f9ba131c.zip
*: centralize error handling
Diffstat (limited to 'src/common')
-rw-r--r--src/common/error.c29
-rw-r--r--src/common/error.h13
2 files changed, 41 insertions, 1 deletions
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 <stddef.h>
+// 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);