This PR changes the indexer macro to allow writing functions with a Result type and adds a mechanism to extract the error message from the WASM module. This is done the same way as with panic hook—by storing the message in a static mutString.
The error message automatically includes the block height as well as the name of the failing handler. Multiple errors from multiple handlers can be reported at once.
Testing steps
Deploy an indexer that returns an Err:
use anyhow::Context;
#[indexer(manifest = "examples/fuel-explorer/fuel-explorer/fuel_explorer.manifest.yaml")]
pub mod explorer_index {
// Returns Result
fn index_block_3(_block_data: BlockData) -> Result<(), String> {
Err("Bleep Bleep. Error. Bleep.".to_string())
}
// Or anyhow::Result
fn index_block_2(block_data: BlockData) -> anyhow::Result<()> {
index_block_2_inner(&block_data).with_context(|| {
format!("failed at height {}", block_data.height)
})
}
// Returns ()
fn index_block(block_data: BlockData) {
// stays the same
}
}
Check the status:
cargo run -p forc-index -- status
It should display the error, and the context:
✅ Successfully fetched service health:
client status: OK
database status: OK
uptime: 2m 36s
Indexers:
─ fuellabs
├─ explorer
| • id: 107
| • created at: 2023-10-19 19:23:02.325661 UTC (4days 50m 11s ago)
| • status: error
| • status message:
| At height 1:
| index_block_3 failed with an error: Bleep Bleep. Error. Bleep.
| index_block_2 failed with an error: failed at height 1
|
└─ hello_world
• id: 99
• created at: 2023-10-17 16:06:58.930780 UTC (6days 4h 6m 14s ago)
• status: running
• status message:
Indexed 940840 blocks
Please provide the exact testing steps for the reviewer(s) if this PR requires testing.
Changelog
Change the codegen to allow the handler function to either return () or Result type
Description
Closes #1409.
This PR changes the
indexer
macro to allow writing functions with aResult
type and adds a mechanism to extract the error message from the WASM module. This is done the same way as with panic hook—by storing the message in astatic mut
String
.The error message automatically includes the block height as well as the name of the failing handler. Multiple errors from multiple handlers can be reported at once.
Testing steps
Deploy an indexer that returns an
Err
:Check the status:
It should display the error, and the context:
Please provide the exact testing steps for the reviewer(s) if this PR requires testing.
Changelog
()
orResult
type