Skip to content

Register custom exceptions for Python bindings#6

Merged
gemenerik merged 2 commits into
mainfrom
rik/exceptions
Mar 9, 2026
Merged

Register custom exceptions for Python bindings#6
gemenerik merged 2 commits into
mainfrom
rik/exceptions

Conversation

@gemenerik
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces dedicated Python exception types for the Rust-backed cflib2 bindings, so Python callers can catch specific Crazyflie error conditions rather than a generic runtime error.

Changes:

  • Add a set of custom PyO3 exception types mirroring crazyflie_lib::Error variants and map Rust errors to these Python exceptions.
  • Register the exception types in the _rust Python module during module initialization.
  • Re-export the exceptions from cflib2/__init__.py and include them in __all__.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
rust/src/lib.rs Registers the new exception types with the _rust module at import time.
rust/src/error.rs Defines custom exceptions, registers them on the module, and updates to_pyerr to return specific exception subclasses.
cflib2/init.py Re-exports the new exceptions at the package root and updates __all__.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread rust/src/error.rs Outdated
Comment thread rust/src/error.rs
Comment thread cflib2/__init__.py
Comment thread cflib2/__init__.py
@gemenerik gemenerik merged commit b2948b7 into main Mar 9, 2026
1 check passed
@gemenerik gemenerik deleted the rik/exceptions branch March 9, 2026 14:50
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.

2 participants