Skip to content

Commit

Permalink
Log httpx errors with repr (#1188)
Browse files Browse the repository at this point in the history
Some httpx errors have empty descriptions, e.g.
`ReadError("")`, so logging with `str` is not
informative. Logging with `repr` will allow to see
the exception type.
  • Loading branch information
jvstme authored Apr 30, 2024
1 parent d5c56f1 commit e50202d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gateway/src/dstack/gateway/core/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def has_access(self, project: str, token: str) -> bool:
if resp.status_code == 200:
return True
except httpx.RequestError as e:
logger.debug("Failed to check access: %s", e)
logger.debug("Failed to check access: %r", e)
return False


Expand Down
8 changes: 4 additions & 4 deletions src/dstack/_internal/server/services/gateways/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ async def register_service(session: AsyncSession, run_model: RunModel):
except SSHError:
raise ServerClientError("Gateway tunnel is not working")
except httpx.RequestError as e:
raise GatewayError(f"Gateway is not working: {e}")
raise GatewayError(f"Gateway is not working: {e!r}")


async def register_replica(
Expand All @@ -382,7 +382,7 @@ async def register_replica(
)
logger.info("%s: replica is registered for service %s", fmt(job_model), run.id.hex)
except (httpx.RequestError, SSHError) as e:
raise GatewayError(str(e))
raise GatewayError(repr(e))


async def unregister_service(session: AsyncSession, run_model: RunModel):
Expand All @@ -400,7 +400,7 @@ async def unregister_service(session: AsyncSession, run_model: RunModel):
# ignore if service is not registered
logger.warning("%s: unregistering service: %s", fmt(run_model), e)
except (httpx.RequestError, SSHError) as e:
raise GatewayError(str(e))
raise GatewayError(repr(e))


async def unregister_replica(session: AsyncSession, job_model: JobModel):
Expand Down Expand Up @@ -431,7 +431,7 @@ async def unregister_replica(session: AsyncSession, job_model: JobModel):
# ignore if replica is not registered
logger.warning("%s: unregistering replica from service: %s", fmt(job_model), e)
except (httpx.RequestError, SSHError) as e:
raise GatewayError(str(e))
raise GatewayError(repr(e))


async def get_gateway_connection(
Expand Down

0 comments on commit e50202d

Please sign in to comment.