FuelLabs / fuel-indexer

🗃 The Fuel indexer is a standalone service that can be used to index various components of the Fuel blockchain.
https://docs.fuel.network/docs/indexer/
140 stars 66 forks source link

enhancement: extract better error messages from indexers #1435

Closed lostman closed 10 months ago

lostman commented 10 months ago

Description

Closes #1434.

This PR improves the error messages from indexers. Block height, transaction ID, the name of decoded struct, failing handlers, etc., are automatically included in the error output.

This is implemented using anyhow with the error propagating upwards, accumulating more context.

Since we now use anyhow internally, it is also added to indexer's Cargo.toml (existing users will have to update manually).

Since #1425, users can also use Result type in the handler functions, so having anyhow already included should prove useful (the handlers can return (), or Result).

cargo run -p forc-index -- status

✅ Successfully fetched service health:

client status: OK
database status: OK
uptime: 44m 38s

Indexers:

┌─ fuellabs
|  ├─ explorer
|  |  • id: 107
|  |  • created at: 2023-10-19 19:23:02.325661 UTC (5days 16h 15m 35s ago)
|  |  • status: error
|  |  • status message:
|  |      Failed processing Block #128821
|  |
|  |      Caused by:
|  |          Failed executing index_block_3()
|  |
|  |          Caused by:
|  |              Another error.
|  |
|  |          Failed executing index_block_2()
|  |
|  |          Caused by:
|  |              Bleep blop Error. Bleep.
|  |
|  └─ hello_world
|     • id: 99
|     • created at: 2023-10-17 16:06:58.930780 UTC (7days 19h 31m 39s ago)
|     • status: running
|     • status message:
|         Indexed 1401240 blocks
|
└─ other
   └─ other_indexer
      • id: 108
      • created at: 2023-10-24 14:26:00.129558 UTC (21h 12m 37s ago)
      • status: error
      • status message:
          Failed processing Block #4000231

          Caused by:
              0: Failed processing Transaction 1d0fb5d1bee5534a1f904d9ff511eae80f219538a1d389728779106f2cf550b4
              1: [codegen] Failed decoding struct SomeStruct
              2: Invalid data: tried to read 64 bytes from response but only had 32 remaining!

Testing steps

Same testing steps as #1425.

The following handlers can be added to fuel-explorer:

    fn index_block_3(_block_data: BlockData) -> anyhow::Result<()> {
        anyhow::bail!("Another error.".to_string())
    }

    fn index_block_2(_block_data: BlockData) -> anyhow::Result<()> {
        anyhow::bail!("Bleep blop Error. Bleep.".to_string())
    }

And then, after building and deploying, the status output should be as above.

The other_indexer is an example of failing codegen, which is harder to reproduce but can be done based on: https://github.com/FuelLabs/fuel-indexer/issues/1424

Changelog

Please add neat Changelog info here, according to our Contributor's Guide.

lostman commented 10 months ago

Maciejs-MBP.Home-2023-10-25.indexer-qa.txt

@ra0x3 ⬆️