Skip to content

Commit

Permalink
fix: better error messages in sentry_transport_curl
Browse files Browse the repository at this point in the history
Up to now we only printed the numeric error-code returned by
`curl_easy_perform()` which isn't sensationally helpful to our users.

We now also print the contents of a `CURLOPT_ERRORBUFFER` and fall back
to `curl_easy_strerror()` in case the error buffer is empty.
  • Loading branch information
supervacuus committed Dec 9, 2022
1 parent bf4c56a commit 6f57b92
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/transports/sentry_transport_curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ sentry__curl_send_task(void *_envelope, void *_state)
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)req->body_len);
curl_easy_setopt(curl, CURLOPT_USERAGENT, SENTRY_SDK_USER_AGENT);

char error_buf[CURL_ERROR_SIZE];
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buf);

struct header_info info;
info.retry_after = NULL;
info.x_sentry_rate_limits = NULL;
Expand Down Expand Up @@ -205,8 +208,17 @@ sentry__curl_send_task(void *_envelope, void *_state)
sentry__rate_limiter_update_from_429(state->ratelimiter);
}
} else {
SENTRY_WARNF(
"sending via `curl_easy_perform` failed with code `%d`", (int)rv);
size_t len = strlen(error_buf);
if (len) {
if (error_buf[len - 1] == '\n') {
error_buf[len - 1] = 0;
}
SENTRY_WARNF("`curl_easy_perform` failed with code `%d`: %s",
(int)rv, error_buf);
} else {
SENTRY_WARNF("`curl_easy_perform` failed with code `%d`: %s",
(int)rv, curl_easy_strerror(rv));
}
}

curl_slist_free_all(headers);
Expand Down

0 comments on commit 6f57b92

Please sign in to comment.