GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(huggingface_hub, cohere): stop swallowing stream iteration errors by intertermux-code · Pull Request #7946 · getsentry/sentry-python

Conversation

@intertermux-code

@intertermux-code intertermux-code commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

The HuggingFace Hub and Cohere streaming iterators wrapped the entire for chunk in res: ... yield chunk loop in capture_internal_exceptions(), which catches every exception — including provider errors raised mid-iteration. The loop ended normally, the truncated answer looked complete, and nothing was reported.

Fix (following the repo's own _capture_exception + span-finish + reraise pattern from the non-streaming paths): iteration/yield now runs outside capture_internal_exceptions — only Sentry's span-data bookkeeping stays inside it. A try/except around the loop records the provider error, finishes the span with error status, and re-raises so the app sees the same exception as without Sentry.

Verified: 4 new regression tests (test_streaming_chat_iteration_error_propagates x2, test_text_generation_streaming_iteration_error_propagates, test_chat_completion_streaming_iteration_error_propagates) fail on pristine code with DID NOT RAISE (exception swallowed) and pass with the fix. Cohere suite 76/76 green, ruff clean, mypy shows no new errors.

Fixes #7889.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@intertermux-code
fix(huggingface_hub, cohere): stop swallowing stream iteration errors
17a1c02
The streaming iterators wrapped the whole chunk loop in
capture_internal_exceptions(), which catches everything including
provider errors raised mid-iteration, so a truncated answer looked
complete and nothing was reported. Run iteration/yield outside it
(only span bookkeeping stays inside), record the provider error,
finish the span with error status, and re-raise.

Fixes getsentry#7889.
@intertermux-code
intertermux-code requested a review from a team as a code owner October 12, 2026 04:29
alexander-alderman-webb
alexander-alderman-webb requested changes Oct 12, 2026
View reviewed changes
Comment thread sentry_sdk/integrations/cohere.py Outdated
Comment on lines +270 to +275
except Exception as e:
exc_info = sys.exc_info()
with capture_internal_exceptions():
_capture_exception(e)
span.__exit__(*exc_info)
reraise(*exc_info)

@alexander-alderman-webb alexander-alderman-webb Oct 12, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Capturing an exception here changed behavior.
We just want to let iterator exceptions bubble out, no capture needed here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@intertermux-code intertermux-code Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done — removed the capture. The exception now just bubbles out after the span finishes with error status, and I made the same change in both huggingface_hub streaming iterators for consistency. Tests updated to assert propagation + span status only.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@intertermux-code
fix: stop capturing mid-stream iteration errors as Sentry events
b6c22ec
Per review: iterator exceptions should just bubble out. The span still
finishes with error status and the exception re-raises, but we no longer
send the provider error as a Sentry event -- that was behavior change
versus running without the SDK.

Same change in both huggingface_hub streaming iterators for consistency;
the three regression tests now assert propagation + span status only.
@alexander-alderman-webb

alexander-alderman-webb commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Can you split up the PR to create separate changes for huggingface_hub and cohere.
We also don't need regression tests since they would just add cruft to the test suite in this case.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexander-alderman-webb alexander-alderman-webb closed this Oct 13, 2026
This was referenced Oct 13, 2026
fix(cohere): Stop swallowing exceptions during stream iteration #8017
Merged
fix(huggingface_hub): Stop swallowing exceptions during stream iteration #8018
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@alexander-alderman-webb alexander-alderman-webb alexander-alderman-webb requested changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Hugging Face Hub and Cohere integrations swallow errors raised while iterating a stream

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@intertermux-code @alexander-alderman-webb
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.