1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! 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:
//!
//! ```rust
//! # pub type Block = ();
//! # mod pb { pub type Custom = (); };
//! // **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:
//!
//! ```rust
//! # pub type Block = ();
//! # mod pb { pub type Custom = (); };
//! 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");
//! }
//!```
/// Error proxy for Substreams, simply a type alias to [anyhow::Error].
///
/// See module [crate::errors] level documentation for more information.
pub type Error = Error;