Skip to content

[executor] All public methods return anyhow::Result — callers cannot distinguish recoverable from fatal errors #163

@obchain

Description

@obchain

PR: #41 (feat/executor: transaction builder + eth_call simulator)
File: crates/charon-executor/src/builder.rs, crates/charon-executor/src/simulation.rs
Refs #41

Problem

Every public method in charon-executor returns anyhow::Result:

  • encode_calldata -> Result
  • build_tx -> Result
  • sign -> Result
  • simulate -> Result<()>

The executor pipeline must distinguish:

  1. Drop this opportunity, try next: simulation revert (position no longer liquidatable), transient nonce race.
  2. Abort the pipeline: signer failure, chain ID mismatch, provider disconnected.

Without typed errors, callers must either treat all errors as fatal (abort on transient nonce race) or all as recoverable (swallow signer failures silently). Neither is correct.

Repo convention

PR #28 (lending trait), PR #39 (flashloan router): library crates expose thiserror enums. anyhow is for application-layer main functions, not library API boundaries.

Fix

Add thiserror to workspace dependencies and charon-executor/Cargo.toml. Define typed error enums:

#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum BuilderError {
    #[error("nonce fetch failed: {0}")]
    NonceFetch(#[source] alloy::transports::TransportError),
    #[error("signing failed: {0}")]
    Signing(#[source] alloy::signers::Error),
    #[error("fee invariant violated: priority {0} > max {1}")]
    InvalidFees(u128, u128),
}

#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SimulationError {
    #[error("simulation reverted: {0}")]
    Reverted(String),
    #[error("provider error: {0}")]
    Provider(#[source] alloy::transports::TransportError),
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglayer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p1-coreCore MVP scopestatus:readyScoped and ready to pick up

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions