-
Notifications
You must be signed in to change notification settings - Fork 665
Specific Exceptions: Adapting cantact interface #1153
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
Conversation
Part of #1046. Also publicly exposes a new exception helper: `error_check` that was previously part of the `usb2can` interface.
Codecov Report
@@ Coverage Diff @@
## develop #1153 +/- ##
===========================================
- Coverage 70.48% 70.46% -0.03%
===========================================
Files 79 79
Lines 7684 7688 +4
===========================================
+ Hits 5416 5417 +1
- Misses 2268 2271 +3 |
| set_bit_timing = Mock() | ||
| set_enabled = Mock() | ||
| set_monitor = Mock() | ||
| start = Mock() |
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.
This was duplicated
|
This PR is important since I need the exception helper |
| @contextmanager | ||
| def error_check( | ||
| error_message: Optional[str] = None, | ||
| exception_type: Type[CanError] = CanOperationError, | ||
| ) -> None: | ||
| """Catches any exceptions and turns them into the new type while preserving the stack trace.""" | ||
| try: | ||
| yield | ||
| except Exception as error: | ||
| if error_message is None: | ||
| raise exception_type(str(error)) from error | ||
| else: | ||
| raise exception_type(error_message) from error |
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.
Nice
Part of #1046.
Also publicly exposes a new exception helper
error_checkwhich was previously part of theusb2caninterface.