Skip to content

Commit

Permalink
Merge pull request #370 from lsst-sqre/tickets/DM-48760
Browse files Browse the repository at this point in the history
DM-48760: Simplify if underlying exception has no message
  • Loading branch information
rra authored Feb 4, 2025
2 parents f5feb42 + cf56c70 commit 13fbe79
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ Changes for the upcoming release can be found in [changelog.d](https://github.co

### New features

- Sentry instrumentation helpers

- Add a new `safir.sentry` module that provides helper functions and custom exception types for improved Sentry integration.
- Allow the encryption key to be passed to `safir.redis.EncryptedPydanticRedisStorage` as a `pydantic.SecretStr` instead of `str`. This allows easier integration with secrets that come from Pydantic-parsed settings.

<a id='changelog-9.1.1'></a>
Expand Down
9 changes: 5 additions & 4 deletions safir/src/safir/sentry/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,16 @@ def from_exception(cls, exc: HTTPError, user: str | None = None) -> Self:
body=exc.response.text,
)
else:
message = f"{type(exc).__name__}: {exc!s}"
exc_name = type(exc).__name__
message = f"{exc_name}: {exc!s}" if str(exc) else exc_name

# All httpx.HTTPError exceptions have a slot for the request,
# initialized to None and then sometimes added by child
# constructors or during exception processing. The request
# property is a property method that raises RuntimeError if
# request has not been set, so we can't just check for None.
# Hence this approach of attempting to use the request and falling
# back on reporting less data if that raised any exception.
# request has not been set, so we can't just check for None. Hence
# this approach of attempting to use the request and falling back
# on reporting less data if that raised any exception.
try:
return cls(
message,
Expand Down
9 changes: 5 additions & 4 deletions safir/src/safir/slack/blockkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,16 @@ def from_exception(cls, exc: HTTPError, user: str | None = None) -> Self:
body=exc.response.text,
)
else:
message = f"{type(exc).__name__}: {exc!s}"
exc_name = type(exc).__name__
message = f"{exc_name}: {exc!s}" if str(exc) else exc_name

# All httpx.HTTPError exceptions have a slot for the request,
# initialized to None and then sometimes added by child
# constructors or during exception processing. The request
# property is a property method that raises RuntimeError if
# request has not been set, so we can't just check for None.
# Hence this approach of attempting to use the request and falling
# back on reporting less data if that raised any exception.
# request has not been set, so we can't just check for None. Hence
# this approach of attempting to use the request and falling back
# on reporting less data if that raised any exception.
try:
return cls(
message,
Expand Down

0 comments on commit 13fbe79

Please sign in to comment.