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

Gracefully fail attachment path not found case #3337

Merged
merged 1 commit into from
Jul 24, 2024
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
4 changes: 1 addition & 3 deletions sentry_sdk/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ def get_bytes(self):
self.bytes = f.read()
elif self.json is not None:
self.bytes = json_dumps(self.json)
else:
self.bytes = b""
return self.bytes
return self.bytes or b""

@property
def inferred_content_type(self):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,22 @@ def test_attachments(sentry_init, capture_envelopes):
assert pyfile.payload.get_bytes() == f.read()


@pytest.mark.tests_internal_exceptions
def test_attachments_graceful_failure(
sentry_init, capture_envelopes, internal_exceptions
):
sentry_init()
envelopes = capture_envelopes()

with configure_scope() as scope:
scope.add_attachment(path="non_existent")
capture_exception(ValueError())

(envelope,) = envelopes
assert len(envelope.items) == 2
assert envelope.items[1].payload.get_bytes() == b""


def test_integration_scoping(sentry_init, capture_events):
logger = logging.getLogger("test_basics")

Expand Down
Loading