Skip to content

Commit

Permalink
gvfs-helper: better handling of network errors
Browse files Browse the repository at this point in the history
Add trace2 message for CURL and HTTP errors.

Fix typo reporting network error code back to gvfs-helper-client.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
  • Loading branch information
jeffhostetler authored and dscho committed Nov 3, 2023
1 parent 38d9949 commit 822bcb7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions gvfs-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,16 @@ static void gh__response_status__set_from_slot(
strbuf_addf(&status->error_message, "%s (curl)",
curl_easy_strerror(status->curl_code));
status->ec = GH__ERROR_CODE__CURL_ERROR;

trace2_data_string("gvfs-helper", NULL,
"error/curl", status->error_message.buf);
} else {
strbuf_addf(&status->error_message, "HTTP %ld Unexpected",
status->response_code);
status->ec = GH__ERROR_CODE__HTTP_UNEXPECTED_CODE;

trace2_data_string("gvfs-helper", NULL,
"error/http", status->error_message.buf);
}

if (status->ec != GH__ERROR_CODE__OK)
Expand Down Expand Up @@ -2035,7 +2041,7 @@ static enum gh__error_code do_sub_cmd__get(int argc, const char **argv)
}

/*
* Handle the 'get' command when in "server mode". Only call error()
* Handle the 'get' command when in "server mode". Only call error() and set ec
* for hard errors where we cannot communicate correctly with the foreground
* client process. Pass any actual data errors (such as 404's or 401's from
* the fetch back to the client process.
Expand Down Expand Up @@ -2107,10 +2113,15 @@ static enum gh__error_code do_server_subprocess_get(void)
goto cleanup;
}

/*
* We only use status.ec to tell the client whether the request
* was complete, incomplete, or had IO errors. We DO NOT return
* this value to our caller.
*/
err = 0;
if (ec == GH__ERROR_CODE__OK)
if (status.ec == GH__ERROR_CODE__OK)
err = packet_write_fmt_gently(1, "ok\n");
else if (ec == GH__ERROR_CODE__HTTP_404)
else if (status.ec == GH__ERROR_CODE__HTTP_404)
err = packet_write_fmt_gently(1, "partial\n");
else
err = packet_write_fmt_gently(1, "error %s\n",
Expand Down Expand Up @@ -2337,6 +2348,7 @@ int cmd_main(int argc, const char **argv)
usage_with_options(main_usage, main_options);

trace2_cmd_name("gvfs-helper");
packet_trace_identity("gvfs-helper");

setup_git_directory_gently(NULL);

Expand Down

0 comments on commit 822bcb7

Please sign in to comment.