Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: full anyhow::Result<()> support in indexers #1425

Merged
merged 3 commits into from
Oct 24, 2023

Conversation

lostman
Copy link
Contributor

@lostman lostman commented Oct 20, 2023

Description

Closes #1409.

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 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:

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

@lostman lostman force-pushed the maciej/1409-full-error-support-in-indexers branch from 17e8f75 to 94feba4 Compare October 20, 2023 12:12
@lostman lostman self-assigned this Oct 20, 2023
@lostman lostman force-pushed the maciej/1409-full-error-support-in-indexers branch 3 times, most recently from 8f220d7 to b1c0f44 Compare October 21, 2023 17:18
@lostman lostman marked this pull request as ready for review October 23, 2023 10:26
Copy link
Contributor

@deekerno deekerno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally like this change. However, I am a bit concerned with requiring people to use a Result; most of that concern is from whether we can expect someone to know how to use it. Is there any way that a user can still do something like a regular fn index_block(...) without having the handler return a Result?

Copy link
Contributor

@ra0x3 ra0x3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I'll echo @deekerno a bit here
  • anyhow::Result should be changed to just Result in all cases where possible
  • And since all handler functions are returning Result<()> this seems a bit...odd - as it's only used to report errors that might have happened
    • Not saying that's not important, but the UX seems a bit off

@lostman lostman force-pushed the maciej/1409-full-error-support-in-indexers branch from f803a10 to 5819f1c Compare October 23, 2023 20:17
ra0x3
ra0x3 previously approved these changes Oct 23, 2023
Copy link
Contributor

@ra0x3 ra0x3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 🔥 Will defer to @deekerno

Copy link
Contributor

@ra0x3 ra0x3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deekerno deekerno merged commit a7aeb59 into develop Oct 24, 2023
19 checks passed
@deekerno deekerno deleted the maciej/1409-full-error-support-in-indexers branch October 24, 2023 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add UserError WasmIndexerError code and extract an error message from WASM
3 participants