Error handling
This commit is contained in:
parent
3b584f74a3
commit
cd520b5fc6
8
main.c
8
main.c
@ -89,7 +89,7 @@ static void export_book(const char path[], Book* book) {
|
||||
do {
|
||||
EB_Error_Code error;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ static void export_book(const char path[], Book* book) {
|
||||
eb_initialize_book(&eb_book);
|
||||
|
||||
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_library();
|
||||
break;
|
||||
@ -146,13 +146,13 @@ static void export_book(const char path[], Book* book) {
|
||||
export_subbook(&eb_book, subbook);
|
||||
}
|
||||
else {
|
||||
strcpy(subbook->error, eb_error_message(error));
|
||||
fprintf(stderr, "Failed to set subbook: %s\n", eb_error_message(error));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
8
util.c
8
util.c
@ -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));
|
||||
}
|
||||
|
||||
if (strlen(subbook->error) > 0) {
|
||||
json_object_set_new(subbook_json, "error", json_string(subbook->error));
|
||||
}
|
||||
|
||||
json_t* entry_json_array = json_array();
|
||||
for (int i = 0; i < subbook->entry_count; ++i) {
|
||||
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, "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();
|
||||
for (int i = 0; i < book->subbook_count; ++i) {
|
||||
json_t* subbook_json = json_object();
|
||||
|
Loading…
Reference in New Issue
Block a user