neocities.h

a C library for interacting with Neocities' API
git clone https://github.com/tanguyandreani/neocities.h
Log | Files | Refs | README | LICENSE

print_error_msg.h (2959B)


      1 #define M(m) \
      2   fprintf(stderr, "error %d: " m, err); \
      3   break
      4 
      5 void neocities_print_error_message(enum neocities_low_level_error err)
      6 {
      7     switch (err) {
      8 
      9     case NEOCITIES_LLVL_OK:
     10         M("everything went okay internally, but it seems"
     11           " neocities reported an error, res.data.error.type should be"
     12           " printed after this");
     13     case NEOCITIES_LLVL_ERR_CURL_GLOBAL_INIT:
     14     case NEOCITIES_LLVL_ERR_CURL_EASY_INIT:
     15     case NEOCITIES_LLVL_ERR_CURL_MIME_INIT:
     16     case NEOCITIES_LLVL_ERR_CURL_MIME_ADDPART:
     17     case NEOCITIES_LLVL_ERR_CURL_MIME_NAME:
     18     case NEOCITIES_LLVL_ERR_CURL_MIME_DATA:
     19     case NEOCITIES_LLVL_ERR_CURL_SLIST_APPEND:
     20     case NEOCITIES_LLVL_ERR_CURL_EASY_SETOPT:
     21     case NEOCITIES_LLVL_ERR_CURL_EASY_PERFORM:
     22         M("libcurl failed, program should probably terminate now");
     23     case NEOCITIES_LLVL_ERR_CURL_MIME_FILEDATA:
     24         M("there is an issue with the file you want to upload");
     25     case NEOCITIES_LLVL_ERR_UNSUPPORTED_DELETE:
     26         M("delete is currently unsupported");
     27     case NEOCITIES_LLVL_ERR_BAD_ACTION:
     28         M("expected action to be a member of neocities_action");
     29     case NEOCITIES_LLVL_ERR_CURL_BUF_INIT:
     30         M("malloc failed in curl_buffer_init()");
     31     case NEOCITIES_LLVL_ERR_JSON_TOKENER_PARSE:
     32         M("json_tokener_parse_ex() failed in neocities_api()");
     33     case NEOCITIES_LLVL_ERR_RECEIVED_UNSUPPORTED_JSON:
     34         M("neocities responded with valid data which i can't understand");
     35     case NEOCITIES_LLVL_ERR_RECEIVED_INVALID_JSON:
     36         M("neocities responded with invalid json data");
     37     case NEOCITIES_LLVL_ERR_MALLOC_FAIL:
     38         M("out of memory");
     39     case NEOCITIES_LLVL_ERR_EXPECTED_STRING:
     40         M("expected the json object to be a string but got something else");
     41     case NEOCITIES_LLVL_ERR_EXPECTED_BOOL:
     42         M("expected the json object to be a boolean but got something else");
     43     case NEOCITIES_LLVL_ERR_EXPECTED_INT:
     44         M("expected the json object to be an int but got something else");
     45     case NEOCITIES_LLVL_ERR_EXPECTED_ARRAY:
     46         M("expected the json object to be an array but got something else");
     47     case NEOCITIES_LLVL_ERR_EXPECTED_STRING_OR_NULL:
     48         M("expected the json object to be a string or to be null but got"
     49           " something else");
     50     case NEOCITIES_LLVL_ERR_EXPECTED_OBJECT:
     51         M("expected the json object to be an object but got something else");
     52     case NEOCITIES_LLVL_ERR_RECEIVED_SOMETHING_ELSE:
     53         M("the type guessed by neocities_json_to_struct() doesn't match"
     54           " with the request that was made");
     55     default:
     56         return;
     57     }
     58 
     59     fputc('\n', stderr);
     60 
     61     return;
     62 }
     63 
     64 void neocities_print_error_message_api(enum neocities_api_level_error err)
     65 {
     66     switch (err) {
     67 
     68     case SITE_NOT_FOUND:
     69         M("site not found");
     70     case UNSUPPORTED_ERROR:
     71         M("unknow (yet) error");
     72     default:
     73         return;
     74     }
     75     fputc('\n', stderr);
     76 
     77     return;
     78 }
     79 
     80 #undef M