Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions can/interfaces/systec/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ def __init__(self, result, func, arguments):
self.func = func
self.arguments = arguments

message = self._error_message_mapping.get(result, "unknown")
result_code = result.value
message = self._error_message_mapping.get(result_code, "unknown")
super().__init__(
message=f"Function {func.__name__} (called with {arguments}): {message}",
error_code=result.value,
error_code=result_code,
)

@property
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/2077.fixed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed Systec errors raising ``TypeError`` instead of reporting the underlying USB-CAN return code.
11 changes: 11 additions & 0 deletions test/test_systec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import can
from can.interfaces.systec import ucan, ucanbus
from can.interfaces.systec.constants import ReturnCode
from can.interfaces.systec.exceptions import UcanError
from can.interfaces.systec.ucan import *


Expand Down Expand Up @@ -46,6 +48,15 @@ def test_bus_creation(self):
self.assertTrue(ucan.UcanGetHardwareInfoEx2.called)
self.assertTrue(ucan.UcanSetAcceptanceEx.called)

def test_error_preserves_ctypes_return_code_message(self):
def failing_function():
pass

error = UcanError(ReturnCode(ReturnCode.ERR_ILLPARAM), failing_function, ())

self.assertEqual(error.error_code, ReturnCode.ERR_ILLPARAM)
self.assertIn("wrong parameter handed over to the function", str(error))

def test_bus_shutdown(self):
self.bus.shutdown()
self.assertTrue(ucan.UcanDeinitCanEx.called)
Expand Down