Skip to content
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

Python exceptions don't preserve class #84

Open
wusspuss opened this issue Jan 29, 2022 · 2 comments
Open

Python exceptions don't preserve class #84

wusspuss opened this issue Jan 29, 2022 · 2 comments

Comments

@wusspuss
Copy link

wusspuss commented Jan 29, 2022

Not sure if this is the intended behavior
{1:2,4:5}[6] in regular python will give something like

Traceback (most recent call last):
  <traceback here ...>
KeyError: 6

While calling python through tohil will produce

'6' (error in python object call)
from python code executed by tohil
<tracback here ...>

That '6' may be quite confusing, and potentially important information is lost about the exception (the fact that it's a keyerror). Since this behavior works fine and makes sense for some cases like say ZeroDivisionError: division by zero -> division by zero, I don't know if it is indeed intended. However, even tcl's own dict get {1 2} 3 won't just say 3, rather key "3" not known in dictionary.
Would it be ok to make tohil return the exception class name along the description?

@wusspuss
Copy link
Author

Would a PR changing the behavior to smth like KeyError 6 be accepted? Tests would have to be updated and I don't think backwards compatibility would be possible

@NasaGeek
Copy link
Member

We do capture the exception type, but it's socked away in $errorCode

% tohil::eval {[][0]}
list index out of range
% puts $errorCode
PYTHON IndexError {list index out of range}

I'll think a bit on how best we could include this information in a more visible way.

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