componentize-py
componentize-py copied to clipboard
Improve type mismatch detection and reporting
Currently, if Python code passes the wrong number or types of parameters to the host, or returns a result of an unexpected type, componentize-py generally reacts by panicking and trapping. That's probably unavoidable in most cases, but it should at least print an informative and actionable diagnostic prior to panicking.
@dicej we ran into this today in this function: https://github.com/bytecodealliance/componentize-py/blob/539472b4e6eb6e3d478928d0e4966d75baf0a1dd/runtime/src/lib.rs#L602
Where someone passed a None in instead.
If you have some ideas on how to best surface this, I can work with the team on implementing some improvements here
Yeah, that's a good example where, instead of unwrapping, we should at least panic with an informative message and a Python-level backtrace, e.g. "expected string value, got value of type {}". Should be able to use the traceback library to call into Python and print the backtrace. I don't recall offhand how to get the human-readable type of a value from PyO3, but I'm sure that's possible.