Skip to content

Conversation

@eikek
Copy link
Member

@eikek eikek commented Sep 24, 2025

Try for better error message for failing http calls

Unfortunately, the error message in the cause exception is not much
better. So there is now a HttpClient extending AsyncClient which
injects the request url into the error message and re-raises the
original error.

/deploy

@RenkuBot
Copy link
Contributor

You can access the deployment of this PR at https://renku-ci-ds-1017.dev.renku.ch

@eikek eikek force-pushed the eikek/fix/connect-errors branch from a9ad077 to a37c1fd Compare September 24, 2025 09:16
@eikek eikek marked this pull request as ready for review September 24, 2025 10:19
@eikek eikek requested a review from a team as a code owner September 24, 2025 10:19
Comment on lines 137 to 138
case httpx.RequestError():
formatted_exception = errors.BaseError(message=f"Error on remote connection: {exception}")
Copy link
Member

@leafty leafty Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to create a new class from the httpx client.

Suggested change
case httpx.RequestError():
formatted_exception = errors.BaseError(message=f"Error on remote connection: {exception}")
case httpx.HTTPError():
formatted_exception = errors.BaseError(message=f"Error while performing {exception.request.method} {exception.request.url}: {exception}")

This way we can log the request method and URL without having to modify the httpx classes.

Reference: https://www.python-httpx.org/exceptions/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you. Somehow missed that page :-|

Copy link
Member Author

@eikek eikek Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah now I recalled what I head in mind last week: For making it "least surprise", I wanted this change only to affect the image code. Not using a separate class also means, we get the uri into the error message for every use of the client. Just mentioning it, because potentially there are cases where this is not desired? But I guess it's fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we have to manually handle the error.

  1. By default we say there was an error performing an HTTP request. In the logs and in Sentry we can log the method and URL (and more if needed).
  2. For endpoints were we know we are not leaking information we can try/catch the exception to give the user the method and URL.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly. So you say we should handle it manually on every case? With this (not very great, I admit) wrapper class, at least it would allow to just replace AsyncClient occurrences, could be more convenient.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the client instances could be passed around, which can be hard to track precisely. Explicit handling at the caller site can look redundant but cannot escape to other parts of the code.

Unfortunately, the error message in the cause exception is not much
better. So there is now a `HttpClient` extending `AsyncClient` which
injects the request url into the error message and re-raises the
original error.
@eikek eikek force-pushed the eikek/fix/connect-errors branch from afb8a88 to 9607178 Compare September 30, 2025 11:38

case httpx.RequestError():
req_uri = exception.request.url
formatted_exception = errors.BaseError(message=f"Error on remote connection to {req_uri}: {exception}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: should we also include the method here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants