Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit f2696d5

Browse files
committed
avoid confusing TypeErrors from api calls
After ab5ea4c it was always throwing wrong singature errors like below even if TypeError was caused by some internal issues inside API - it was adding couple extra steps to traceback making errors more noisy. TypeError: Incorrect function arguments provided for library.edit_library attribute 'VersionDate' for entity 'IFC2X3.IfcLibraryInformation' is expecting value of type 'ENTITY INSTANCE', got 'str'.. You specified args (<ifcopenshell.file.file object at 0x0000027EB8E6BCD0>,) and settings {'library': #1=IfcLibraryInformation('Name','Version',$,$,$), 'attributes': {'Name': 'Name', 'Version': 'Version', 'VersionDate': 'VersionDate', 'Location': 'Location', 'Description': 'Description'}} E Correct signature is (file: ifcopenshell.file.file, library: ifcopenshell.entity_instance.entity_instance, attributes: dict[str, typing.Any]) -> None See help(ifcopenshell.api.library.edit_library) for documentation.
1 parent 5e394e1 commit f2696d5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/ifcopenshell-python/ifcopenshell/api/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,18 @@ def wrapper(*args, should_run_listeners: bool = True, **settings):
324324

325325
try:
326326
result = usecase(*args, **settings)
327-
except TypeError as e:
328-
msg = f"Incorrect function arguments provided for {usecase_path}\n{str(e)}. You specified args {args} and settings {settings}\n\nCorrect signature is {inspect.signature(usecase)}\nSee help(ifcopenshell.api.{usecase_path}) for documentation."
327+
except NotImplementedError as e:
328+
if not e.args[0].startswith(f"{usecase.__name__}()"):
329+
# signature errors typically start with function name
330+
# e.g. "TypeError: edit_library() got an unexpected keyword argument 'test'"
331+
# otherwise it's an error inside api call and we shouldn't get in the way
332+
raise e
333+
msg = (
334+
f"Incorrect function arguments provided for {usecase_path}\n{str(e)}. "
335+
f"You specified args {args} and settings {settings}\n\n"
336+
f"Correct signature is {inspect.signature(usecase)}\n"
337+
f"See help(ifcopenshell.api.{usecase_path}) for documentation."
338+
)
329339
raise TypeError(msg) from e
330340

331341
if should_run_listeners:

0 commit comments

Comments
 (0)