poor error message for wrong 1-tuple annotation #108

Closed
opened 2021-11-23 15:48:48 +08:00 by sb10q · 2 comments
Owner

x: tuple[int32] annotations error out with pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: "Expect multiple elements for tuple"

  1. We should not panic from errors in user code
  2. Location should be indicated
  3. Error message should be clearer and indicate the correct syntax for 1-tuple: tuple[(ty, )]. Alternatively we can also accept tuple[ty] for 1-tuples.
``x: tuple[int32]`` annotations error out with ``pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: "Expect multiple elements for tuple"`` 1. We should not panic from errors in user code 2. Location should be indicated 3. Error message should be clearer and indicate the correct syntax for 1-tuple: ``tuple[(ty, )]``. Alternatively we can also accept ``tuple[ty]`` for 1-tuples.
Collaborator

We should not panic from errors in user code

I am sorry that regarding this I am not sure how this should be handled.. since it is an error ultimately captured and unwraped in a rust code that is called from python. Are we able to raise a python error from rust or did I miss anything?

> We should not panic from errors in user code I am sorry that regarding this I am not sure how this should be handled.. since it is an error ultimately captured and unwraped in a rust code that is called from python. Are we able to raise a python error from rust or did I miss anything?
Author
Owner

Are we able to raise a python error from rust or did I miss anything?

Absolutely - when PyO3 functions return a PyResult, Err values are turned into exceptions.
Example: https://git.m-labs.hk/M-Labs/nac3/src/branch/master/nac3artiq/src/lib.rs#L97-L101

> Are we able to raise a python error from rust or did I miss anything? Absolutely - when PyO3 functions return a ``PyResult``, ``Err`` values are turned into exceptions. Example: https://git.m-labs.hk/M-Labs/nac3/src/branch/master/nac3artiq/src/lib.rs#L97-L101
sb10q referenced this issue from a commit 2021-12-22 08:52:20 +08:00
sb10q closed this issue 2021-12-22 17:58:22 +08:00
ychenfo referenced this issue from a commit 2021-12-27 16:57:43 +08:00
Sign in to join this conversation.
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#108
No description provided.