Skip to content

Improve error reporting for calling user-defined functions from the Python scope #521

@shi-eric

Description

@shi-eric

Calling a user-defined function from the Python scope that throws an exception gives an indecipherable error message:

import warp as wp


@wp.func
def bad_function(origin: wp.vec3):
    val = origin / 0
    return val


origin = wp.vec3()
result = bad_function(origin)
print(result)

Output:

  File "/home/eshi/code-projects/warp/warp/context.py", line 333, in __call__
    raise RuntimeError(f"Error calling function '{self.key}', no overload found for arguments {args}")
RuntimeError: Error calling function 'bad_function', no overload found for arguments (<warp.types.vec3f object at 0x74881af6f150>,)

Removing the wp.func decorator gives:

  File "/home/eshi/code-projects/warp/ershi-tests/ignored-user-function-errors/test_2.py", line 5, in bad_function
    val = origin / 0
          ~~~~~~~^~~
  File "/home/eshi/code-projects/warp/warp/types.py", line 253, in __truediv__
    return warp.div(self, y)
           ^^^^^^^^^^^^^^^^^
  File "/home/eshi/code-projects/warp/warp/context.py", line 307, in __call__
    raise RuntimeError(
RuntimeError: Couldn't find a function 'div' compatible with the arguments 'vec3f, int'

In these cases, we should give an error message more like the above.

This is due to the ignoring of exceptions here:

warp/warp/context.py

Lines 330 to 331 in 56a290b

except Exception:
continue

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions