Err instead of panic for host object attribute error #288

Merged
sb10q merged 1 commits from 281-host-obj-attribute-err into master 2022-05-18 06:36:08 +08:00
Collaborator

This is a fix to #281: proper error message is returned now instead of panic

This is a fix to #281: proper error message is returned now instead of panic
sb10q reviewed 2022-05-16 12:34:38 +08:00
@ -674,0 +674,4 @@
Ok(d) => d,
Err(e) => {
if e.is_instance::<PyAttributeError>(py) {
return Ok(Err(format!("{}", e).replace("AttributeError: ", "")));

Why?

Why?

Won't other types of errors have the same issue? I don't see what's special about AttributeError. The default behavior of printing AttributeError("...") seems acceptable to me (for now) and should be simple enough.

Won't other types of errors have the same issue? I don't see what's special about AttributeError. The default behavior of printing ``AttributeError("...")`` seems acceptable to me (for now) and should be simple enough.
Poster
Collaborator

Here I think that it should only catch AttributeError because we are using getattr to get the member of an object, so we are only expecting AttributeError to happen here. Other errors should not happen.

Here I think that it should only catch `AttributeError` because we are using `getattr` to get the member of an object, so we are only expecting `AttributeError` to happen here. Other errors should not happen.
Poster
Collaborator

Hmm maybe it's better to use unreachable! to mark that internal error and panic here?

Hmm maybe it's better to use `unreachable!` to mark that internal error and panic here?
ychenfo force-pushed 281-host-obj-attribute-err from ba0de43526 to 54b7af270d 2022-05-17 01:12:29 +08:00 Compare
Poster
Collaborator

force-pushed to use unreachable! to handle internal error in which exception other than AttributeError are thrown from python interpreter

force-pushed to use `unreachable!` to handle internal error in which exception other than `AttributeError` are thrown from python interpreter

No, there can be other exceptions. For example:

>>> class X:
...   def __getattr__(self, attr):
...     raise TypeError
... 
>>> getattr(X(), "foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in __getattr__
TypeError

Please remove the special-casing.

No, there can be other exceptions. For example: ``` >>> class X: ... def __getattr__(self, attr): ... raise TypeError ... >>> getattr(X(), "foo") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in __getattr__ TypeError ``` Please remove the special-casing.
ychenfo force-pushed 281-host-obj-attribute-err from 54b7af270d to 09820e5aed 2022-05-18 02:54:47 +08:00 Compare
Poster
Collaborator

Please remove the special-casing.

Thanks for pointing this out! Force-pushed to catch all types of exceptions and updated to the latest master branch.

> Please remove the special-casing. Thanks for pointing this out! Force-pushed to catch all types of exceptions and updated to the latest master branch.
sb10q merged commit 09820e5aed into master 2022-05-18 06:36:08 +08:00
sb10q deleted branch 281-host-obj-attribute-err 2022-05-18 06:36:08 +08:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#288
There is no content yet.