Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-48760: Simplify if underlying exception has no message #370

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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