Skip to content

Commit

Permalink
Make the exception message more helpful
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland committed Jul 2, 2024
1 parent 9490fbf commit 410b683
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions canopen/objectdictionary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def export_od(od, dest: Union[str, TextIO, None] = None, doc_type: Optional[str]
from canopen.objectdictionary import eds
return eds.export_dcf(od, dest)
else:
raise ValueError(f"No support for the {doc_type!r} format")
allowed = ", ".join(doctypes)
raise ValueError(
f"Cannot export to the {doc_type!r} format; "
f"supported formats: {allowed}"
)
finally:
# If dest is opened in this fn, it should be closed
if opened_here:
Expand Down Expand Up @@ -89,7 +93,11 @@ def import_od(
return epf.import_epf(source)
else:
doc_type = suffix[1:]
raise ValueError(f"No support for the {doc_type!r} format")
allowed = ", ".join(["eds", "dcf", "epf"])
raise ValueError(
f"Cannot import from the {doc_type!r} format; "
f"supported formats: {allowed}"
)


class ObjectDictionary(MutableMapping):
Expand Down

0 comments on commit 410b683

Please sign in to comment.