Skip to content

Fix bare except in Stream_accept that swallows all exceptions#1632

Open
Andy-Jost wants to merge 1 commit intoNVIDIA:mainfrom
Andy-Jost:fix-stream-accept-bare-except
Open

Fix bare except in Stream_accept that swallows all exceptions#1632
Andy-Jost wants to merge 1 commit intoNVIDIA:mainfrom
Andy-Jost:fix-stream-accept-bare-except

Conversation

@Andy-Jost
Copy link
Contributor

Summary

  • Narrows bare except: pass in Stream_accept to except TypeError with a string check for "__cuda_stream__", so only the "protocol not supported" case is silently handled
  • Buggy __cuda_stream__ implementations, RuntimeError, KeyboardInterrupt, SystemExit, etc. now propagate correctly

Closes #1631

Changes

  • _stream.pyx: Replace except: pass with except TypeError as e: if "__cuda_stream__" not in str(e): raise

Test Coverage

  • Existing Stream_accept and stream protocol tests cover the happy path
  • The change is a strict narrowing of the catch clause; no new behavior is introduced for well-formed objects

Made with Cursor

…#1631)

Narrow the catch from bare `except: pass` to `except TypeError`
with a string check, so that only missing `__cuda_stream__` is
silently handled. Buggy protocol implementations and other
exceptions now propagate correctly.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Andy-Jost Andy-Jost added this to the cuda.core v0.7.0 milestone Feb 17, 2026
@Andy-Jost Andy-Jost added bug Something isn't working P1 Medium priority - Should do cuda.core Everything related to the cuda.core module labels Feb 17, 2026
@Andy-Jost Andy-Jost self-assigned this Feb 17, 2026
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Feb 17, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@Andy-Jost
Copy link
Contributor Author

/ok to test a1614ed

@Andy-Jost Andy-Jost requested a review from cpcloud February 17, 2026 21:57
@Andy-Jost
Copy link
Contributor Author

I found this issue as a follow-on to this comment while searching for other places where try...except was used to swallow exceptions too broadly.

Comment on lines +512 to +514
except TypeError as e:
if "__cuda_stream__" not in str(e):
raise
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cf.

try:
cuda_stream_attr = obj.__cuda_stream__
except AttributeError:
raise TypeError(f"{type(obj)} object does not have a '__cuda_stream__' attribute") from None

@github-actions
Copy link

@Andy-Jost Andy-Jost requested a review from leofang February 17, 2026 22:24
@leofang
Copy link
Member

leofang commented Feb 18, 2026

@Andy-Jost Just to confirm, this PR can wait after we release v0.6.0, or do you want this to be part of v0.6.0 as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module P1 Medium priority - Should do

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stream_accept uses bare except that swallows all exceptions

2 participants