streamingfast / substreams-rs

9 stars 3 forks source link

Ensure that we are able to properly propagate error in Substreams #14

Open maoueh opened 1 year ago

maoueh commented 1 year ago

Right now, it's not easily possible to perform error propagation up to the the Substreams module because the handler module return error is Substreams specific and don't offer conversion from other errors today.

We could add conversion for most standard error, String and support for anyhow::Error, I imagine it will enable error propagation in almost very cases, and cases failing to compile could workaround by wrapping their error with anyhow.

We should actually instead start this task by investigating returning Result<T, anyhow::Error> directly instead. The anyhow::Error can already convert any error type that implemented std::error::Error trait and support cause chain.

It would make life easier for everyone if we could have that. Would even be better is consumer of substreams Rust crate would not have to import anyhow in their Cargo.toml directly, I think we would need to re-export anyhow::Error out of substreams-rs for that so mapping code can still use Result<T, substreams::Error> but that would be actually a anyhow::Error.

If we find out that Result<T, anyhow::Error> creates issue, we would go back to keeping actual Substreams error type and implement a bunch of conversion, specially supporting anyhow::Error and std::error:Error trait.