Skip to content

Ability to convert exceptions into strings #4178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lastmjs opened this issue Sep 21, 2022 · 3 comments
Open

Ability to convert exceptions into strings #4178

lastmjs opened this issue Sep 21, 2022 · 3 comments

Comments

@lastmjs
Copy link

lastmjs commented Sep 21, 2022

I've been working in a strict wasm32-unknown-unknown environment, and I've been having a hard time with exceptions from the vm, as when you print them the string is not very useful at all. I just found vm.print_exception and it has actually useful information in it. This method works great if println works in you environment, but in the wasm32-unknown-unknown environment I'm in I can't use the println macro directly. It would be great if the RustPython errors had a method called something like to_readable_string or something that will do the same thing as vm.print_exception, but instead return the error so that it can be dealt with in other ways.

@youknowone
Copy link
Member

if you don't need traceback, exc can be converted to PyObjectRef and PyObject has repr method.

for exc: PyBaseExceptionRef, exc.to_pyobject(vm).repr(vm) will work

@lastmjs
Copy link
Author

lastmjs commented Oct 11, 2022

Why can't the traceback work without calling vm.print_exception?

@lastmjs
Copy link
Author

lastmjs commented Oct 11, 2022

The messages are definitely better now, had to do this to just get a string:

let err_string: String = err.to_pyobject(vm).repr(vm).unwrap().to_string();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants