1

Error handling

This commit is contained in:
Alex Yatskov 2016-11-16 19:10:44 -08:00
parent 3b584f74a3
commit cd520b5fc6
3 changed files with 4 additions and 16 deletions

8
main.c
View File

@ -89,7 +89,7 @@ static void export_book(const char path[], Book* book) {
do { do {
EB_Error_Code error; EB_Error_Code error;
if ((error = eb_initialize_library()) != EB_SUCCESS) { if ((error = eb_initialize_library()) != EB_SUCCESS) {
strcpy(book->error, eb_error_message(error)); fprintf(stderr, "Failed to initialize library: %s\n", eb_error_message(error));
break; break;
} }
@ -97,7 +97,7 @@ static void export_book(const char path[], Book* book) {
eb_initialize_book(&eb_book); eb_initialize_book(&eb_book);
if ((error = eb_bind(&eb_book, path)) != EB_SUCCESS) { if ((error = eb_bind(&eb_book, path)) != EB_SUCCESS) {
strcpy(book->error, eb_error_message(error)); fprintf(stderr, "Failed to bind book: %s\n", eb_error_message(error));
eb_finalize_book(&eb_book); eb_finalize_book(&eb_book);
eb_finalize_library(); eb_finalize_library();
break; break;
@ -146,13 +146,13 @@ static void export_book(const char path[], Book* book) {
export_subbook(&eb_book, subbook); export_subbook(&eb_book, subbook);
} }
else { else {
strcpy(subbook->error, eb_error_message(error)); fprintf(stderr, "Failed to set subbook: %s\n", eb_error_message(error));
} }
} }
} }
} }
else { else {
strcpy(book->error, eb_error_message(error)); fprintf(stderr, "Failed to get subbook list: %s\n", eb_error_message(error));
} }
eb_finalize_book(&eb_book); eb_finalize_book(&eb_book);

8
util.c
View File

@ -100,10 +100,6 @@ static void encode_subbook(Subbook* subbook, json_t* subbook_json) {
json_object_set_new(subbook_json, "copyright", json_string(subbook->copyright)); json_object_set_new(subbook_json, "copyright", json_string(subbook->copyright));
} }
if (strlen(subbook->error) > 0) {
json_object_set_new(subbook_json, "error", json_string(subbook->error));
}
json_t* entry_json_array = json_array(); json_t* entry_json_array = json_array();
for (int i = 0; i < subbook->entry_count; ++i) { for (int i = 0; i < subbook->entry_count; ++i) {
json_t* entry_json = json_object(); json_t* entry_json = json_object();
@ -120,10 +116,6 @@ static void encode_book(Book* book, json_t* book_json) {
json_object_set_new(book_json, "characterCode", json_string(book->character_code)); json_object_set_new(book_json, "characterCode", json_string(book->character_code));
json_object_set_new(book_json, "discCode", json_string(book->disc_code)); json_object_set_new(book_json, "discCode", json_string(book->disc_code));
if (strlen(book->error) > 0) {
json_object_set_new(book_json, "error", json_string(book->error));
}
json_t* subbook_json_array = json_array(); json_t* subbook_json_array = json_array();
for (int i = 0; i < book->subbook_count; ++i) { for (int i = 0; i < book->subbook_count; ++i) {
json_t* subbook_json = json_object(); json_t* subbook_json = json_object();

4
util.h
View File

@ -48,8 +48,6 @@ typedef struct {
Entry* entries; Entry* entries;
int entry_count; int entry_count;
int entry_cap; int entry_cap;
char error[MAX_ERROR];
} Subbook; } Subbook;
typedef struct { typedef struct {
@ -58,8 +56,6 @@ typedef struct {
Subbook* subbooks; Subbook* subbooks;
int subbook_count; int subbook_count;
char error[MAX_ERROR];
} Book; } Book;
/* /*