Expand description
Error proxy for Substreams.
This crate implements Substreams error that you can return in your Substreams handler.
The Substreams Error implementation is simply a type alias to anyhow::Error. Anyhow is a crate that make it easy to create generic error as well as attaching context to error from library.
For example, let’s say you want to return an error when the decoding fail with in context the input data that failed to decode. You can do it like this:
// **Important** Brings in scope `.context` and `.with_context` methods.
use anyhow::Context;
fn map_handler(params: String, block: Block) -> Result<pb::Custom, substreams::errors::Error> {
let address = substreams::Hex::decode(¶ms).with_context(|| format!("failed to decode address: {}", params))?;
unimplemented!("do something");
}If you want to return a plain error, you can use the anyhow::anyhow! macro:
use anyhow::anyhow;
fn map_handler(params: String, block: Block) -> Result<pb::Custom, substreams::errors::Error> {
if params.len() != 42 {;
return Err(anyhow!("invalid address length"));
}
unimplemented!("do something");
}Type Aliases§
- Error
- Error proxy for Substreams, simply a type alias to anyhow::Error.