From 47bf9de60207aa2bffa58fca54251c5ff421c984 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Thu, 10 Feb 2022 20:32:43 +0000 Subject: [PATCH] Error handling FossilOrigin-Name: 7d76b3601243328c356a06828be47e6003fb5d81bdaba8051065506686b4eee7 --- src/account.c | 9 +++++---- src/fetch.c | 4 ---- src/timeline.c | 10 +++++----- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/account.c b/src/account.c index 71c0620..b41a0a1 100644 --- a/src/account.c +++ b/src/account.c @@ -34,16 +34,17 @@ int mastodont_account(mastodont_t* data, id); storage->needs_cleanup = 0; - res = mastodont_fetch_curl(data, url, &results); + if (mastodont_fetch_curl(data, url, &results) != CURLE_OK) + { + return 1; + } /* TODO cleanup this */ root = cJSON_ParseWithLength(results.response, results.size); if (root == NULL) { - const char* jerror = cJSON_GetErrorPtr(); - if (jerror) - fprintf(stderr, "cJSON_Parse: %s\n", jerror); + res = 1; goto cleanup; } storage->root = root; diff --git a/src/fetch.c b/src/fetch.c index 961c72f..d2026dd 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -60,10 +60,6 @@ int mastodont_fetch_curl(mastodont_t* mstdnt, curl_easy_setopt(mstdnt->curl, CURLOPT_WRITEDATA, results); res = curl_easy_perform(mstdnt->curl); - if (res != CURLE_OK) - { - printf("curl_easy_perform: %s\n", curl_easy_strerror(res)); - } return res; } diff --git a/src/timeline.c b/src/timeline.c index 8494c6e..9e7df18 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -44,14 +44,13 @@ int mastodont_timeline_public(mastodont_t* data, } storage->needs_cleanup = 0; - res = mastodont_fetch_curl(data, "api/v1/timelines/public", &results); + if (mastodont_fetch_curl(data, "api/v1/timelines/public", &results) != CURLE_OK) + return 1; root = cJSON_ParseWithLength(results.response, results.size); if (root == NULL) { - const char* jerror = cJSON_GetErrorPtr(); - if (jerror) - fprintf(stderr, "cJSON_Parse: %s\n", jerror); + res = 1; goto cleanup; } storage->root = root; @@ -60,6 +59,7 @@ int mastodont_timeline_public(mastodont_t* data, if (!cJSON_IsArray(root)) { /* Likely an error */ + res = 1; goto cleanup; } @@ -70,7 +70,7 @@ int mastodont_timeline_public(mastodont_t* data, * sizeof(struct mstdnt_status)); if (*statuses == NULL) { - perror("malloc"); + res = 1; goto cleanup; }