Skip to content

fix(socketcan): include channel in binding errors - #2105

Open
vonpanda wants to merge 1 commit into
hardbyte:mainfrom
vonpanda:fix/socketcan-bind-error-context
Open

vonpanda wants to merge 1 commit into
hardbyte:mainfrom
vonpanda:fix/socketcan-bind-error-context

Conversation

@vonpanda

@vonpanda vonpanda commented Oct 6, 2026 •

Copy link
Copy Markdown

Summary of Changes

  • Include the SocketCAN channel in an OSError raised by bind_socket, while retaining its type, error number, and traceback.
  • Cover device-not-found, permission-denied, and error-without-errno cases, plus a successful bind.
  • Add a changelog fragment.

The channel is included in the exception text so callers that log str(error) see it. This also works on Python 3.10, where exception notes are unavailable.

Related Issues / Pull Requests

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other

Checklist

  • I have followed the contribution guide.
  • I have added tests.
  • I have added a news fragment.
  • All checks and tests pass (tox).

Validation

  • uv run --no-sync python -m pytest test -q -o addopts='': 500 passed, 131 skipped, 32 subtests passed.
  • uv run --no-sync python -m pytest test/test_socketcan.py -q -o addopts='': 10 passed, 3 skipped, 3 subtests passed after the final change.
  • black --check can/interfaces/socketcan/socketcan.py test/test_socketcan.py and git diff --check passed.

ruff check reports seven existing diagnostics on lines outside this patch. I did not run tox.

@mergify

mergify Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make socket binding exceptions more debugable

1 participant