#Error propagation

2 messages · Page 1 of 1 (latest)

woeful dock
#

I have a set of functions that need to return a specific error type: pyo3::PyErr.

The code in the functions contain some i/o, and has the possibility of running into a range of different errors. For example, RedisError, and SendError.

I would love to use the ? operators, generally, and to have the translation from downstream to upstream error happen automatically. I've come up with this as a solution: https://github.com/sondrelg/timely/blob/main/src/semaphore/errors.rs, where I implement my own custom error enum and do this mapping.

I'm still finding this a little tedious though, and since I have two error types to do this for, I've ended up with a lot of duplicated impl code (here is the other one https://github.com/sondrelg/timely/blob/main/src/token_bucket/error.rs).

tl;dr: Is there a better way to achieve this? and/or can this solution be tweaked so it's generic?

silk prairie
#

there is the thiserror crate, which will write much of that for you