improve error handling for achievement unlocks (#11916)

This commit is contained in:
Jamiras 2021-01-20 19:07:48 -08:00 committed by GitHub
parent cff0a4e202
commit 015576b2ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 11 deletions

View File

@ -621,12 +621,34 @@ static void rcheevos_async_task_callback(
retro_task_t* task, void* task_data, void* user_data, const char* error) retro_task_t* task, void* task_data, void* user_data, const char* error)
{ {
rcheevos_async_io_request* request = (rcheevos_async_io_request*)user_data; rcheevos_async_io_request* request = (rcheevos_async_io_request*)user_data;
http_transfer_data_t* data = (http_transfer_data_t*)task_data;
if (!error) if (!error)
{ {
char buffer[224]; char buffer[224] = "";
const http_transfer_data_t* data = (http_transfer_data_t*)task->task_data; if (!data)
if (rcheevos_get_json_error(data->data, buffer, sizeof(buffer)) == RC_OK) {
/* server did not return HTTP headers */
snprintf(buffer, sizeof(buffer), "Server communication error");
}
else if (data->status != 200)
{
/* server returned an error via status code - check to see if it also returned a JSON error */
if (!data->data || rcheevos_get_json_error(data->data, buffer, sizeof(buffer)) != RC_OK)
snprintf(buffer, sizeof(buffer), "HTTP error code: %d", data->status);
}
else if (!data->data || !data->len)
{
/* server sent an empty response without an error status code */
snprintf(buffer, sizeof(buffer), "No response from server");
}
else
{
/* server sent a message - assume its JSON and check for a JSON error */
rcheevos_get_json_error(data->data, buffer, sizeof(buffer));
}
if (buffer[0])
{ {
char errbuf[256]; char errbuf[256];
snprintf(errbuf, sizeof(errbuf), "%s %u: %s", request->failure_message, request->id, buffer); snprintf(errbuf, sizeof(errbuf), "%s %u: %s", request->failure_message, request->id, buffer);
@ -669,6 +691,14 @@ static void rcheevos_async_task_callback(
CHEEVOS_ERR(RCHEEVOS_TAG "%s %u: %s\n", request->failure_message, request->id, error); CHEEVOS_ERR(RCHEEVOS_TAG "%s %u: %s\n", request->failure_message, request->id, error);
} }
if (data)
{
if (data->data)
free(data->data);
free(data);
}
} }
static void rcheevos_activate_achievements(rcheevos_locals_t *locals, static void rcheevos_activate_achievements(rcheevos_locals_t *locals,

View File

@ -4248,7 +4248,7 @@ static void cb_net_generic(retro_task_t *task,
menu->core_buf = NULL; menu->core_buf = NULL;
menu->core_len = 0; menu->core_len = 0;
if (!data || err) if (!data || err || !data->data)
goto finish; goto finish;
menu->core_buf = (char*)malloc((data->len+1) * sizeof(char)); menu->core_buf = (char*)malloc((data->len+1) * sizeof(char));

View File

@ -5947,7 +5947,7 @@ static void handle_discord_join_cb(retro_task_t *task,
struct rarch_state *p_rarch = &rarch_st; struct rarch_state *p_rarch = &rarch_st;
discord_state_t *discord_st = &p_rarch->discord_st; discord_state_t *discord_st = &p_rarch->discord_st;
if (!data || err) if (!data || err || !data->data)
goto finish; goto finish;
data->data = (char*)realloc(data->data, data->len + 1); data->data = (char*)realloc(data->data, data->len + 1);
@ -10648,7 +10648,7 @@ static void handle_translation_cb(
RARCH_LOG("RESULT FROM AI SERVICE...\n"); RARCH_LOG("RESULT FROM AI SERVICE...\n");
#endif #endif
if (!data || error) if (!data || error || !data->data)
goto finish; goto finish;
json = rjson_open_buffer(data->data, data->len); json = rjson_open_buffer(data->data, data->len);

View File

@ -191,15 +191,28 @@ task_finished:
free(tmp); free(tmp);
if (task_get_cancelled(task)) if (task_get_cancelled(task))
{
task_set_error(task, strdup("Task cancelled.")); task_set_error(task, strdup("Task cancelled."));
else if (!task->mute) }
task_set_error(task, strdup("Download failed.")); else
{
data = (http_transfer_data_t*)malloc(sizeof(*data));
data->data = NULL;
data->len = 0;
data->status = net_http_status(http->handle);
task_set_data(task, data);
if (!task->mute)
task_set_error(task, strdup("Download failed."));
}
} }
else else
{ {
data = (http_transfer_data_t*)malloc(sizeof(*data)); data = (http_transfer_data_t*)malloc(sizeof(*data));
data->data = tmp; data->data = tmp;
data->len = len; data->len = len;
data->status = net_http_status(http->handle);
task_set_data(task, data); task_set_data(task, data);
} }

View File

@ -55,6 +55,7 @@ typedef struct
{ {
char *data; char *data;
size_t len; size_t len;
int status;
} http_transfer_data_t; } http_transfer_data_t;
void *task_push_http_transfer(const char *url, bool mute, const char *type, void *task_push_http_transfer(const char *url, bool mute, const char *type,