Skip to content

Improve main entrypoint error reporting - #404

Merged
pablodeymo merged 1 commit into
lambdaclass:mainfrom
dicethedev:fix/main-entrypoint-error-reporting
Jun 1, 2026
Merged

Improve main entrypoint error reporting#404
pablodeymo merged 1 commit into
lambdaclass:mainfrom
dicethedev:fix/main-entrypoint-error-reporting

Conversation

@dicethedev

Copy link
Copy Markdown
Contributor

🗒️ Description / Motivation

  • Replaces panic-based startup error handling in bin/ethlambda with eyre errors and contextual messages.
  • This is needed so initialization failures report useful causes and paths instead of panicking through unwrap/expect.
  • Solves issue Improve error reporting in main entrypoint #100 for the main entrypoint by improving error reporting in non-library binary code.

What Changed

  • Updated bin/ethlambda/src/main.rs.
  • Added eyre::WrapErr usage around startup IO, parsing, tracing setup, RocksDB initialization, validator key loading, and swarm construction.
  • Changed helper functions to return eyre::Result instead of panicking or exiting internally.

Correctness / Behavior Guarantees

  • Startup still fails fast on invalid configuration, keys, storage, or swarm setup.
  • Failure mode changed from panic/internal exit to structured eyre errors with context.
  • No consensus, networking, storage, or RPC behavior changes are intended.

Tests Added / Run

  • No new tests were added.
  • Ran:
    • cargo fmt --check
    • cargo check -p ethlambda
    • cargo test -p ethlambda
    • cargo test -p ethlambda-p2p

Related Issues / PRs

✅ Verification Checklist

  • Ran cargo fmt --check — clean
  • [ x] Ran make fmt — not run
  • [ x] Ran make lint (clippy with -D warnings) — not run
  • [ x] Ran cargo test --workspace --release — not run

@greptile-apps

greptile-apps Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces all unwrap/expect/process::exit startup error paths in bin/ethlambda/src/main.rs with structured eyre::Result propagation, adding contextual messages (including file paths) at each failure site.

  • Helper functions (read_hex_file_bytes, read_validator_config_file, read_bootnodes, read_validator_keys) now return eyre::Result instead of panicking or calling process::exit, and all callsites are updated with ?.
  • Error messages are enriched with file paths and operation context using wrap_err_with, making startup failures significantly easier to diagnose.

Confidence Score: 4/5

Safe to merge — all changes are confined to startup error-path refactoring with no logic or behavior modifications.

The change is a straightforward mechanical refactor of startup error handling. The only notable issue is a redundant map_err before wrap_err_with in the RocksDB open call that needlessly stringifies the error and drops its chain — a cosmetic concern that doesn't affect correctness.

No files require special attention; bin/ethlambda/src/main.rs is the sole changed file and the changes are isolated to error-handling plumbing.

Important Files Changed

Filename Overview
bin/ethlambda/src/main.rs Replaces all unwrap/expect/process::exit startup paths with eyre::Result propagation; one minor redundant map_err for the RocksDB open call, but otherwise clean.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[main] --> B[set_global_default tracing subscriber]
    B -->|Err| Z1[eyre: failed to set global tracing subscriber]
    B --> C[read_hex_file_bytes node_key]
    C -->|Err| Z2[eyre: failed to load node key from path]
    C --> D[read_to_string config_path]
    D -->|Err| Z3[eyre: failed to read genesis config from path]
    D --> E[serde_yaml_ng::from_str GenesisConfig]
    E -->|Err| Z4[eyre: failed to parse genesis config from path]
    E --> F[read_validator_config_file]
    F -->|Err| Z5[eyre: failed to read/parse validator config]
    F --> G[read_bootnodes]
    G -->|Err| Z6[eyre: failed to read/parse bootnodes]
    G --> H[read_validator_keys]
    H -->|Err| Z7[eyre: failed to load validator keys]
    H --> I[create_dir_all data_dir]
    I -->|Err| Z8[eyre: failed to create data directory]
    I --> J[RocksDBBackend::open]
    J -->|Err| Z9[eyre: failed to open RocksDB at path]
    J --> K[build_swarm]
    K -->|Err| Z10[eyre: failed to build swarm]
    K --> L[P2P::spawn — node running]
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
bin/ethlambda/src/main.rs:225-229
Redundant `map_err` before `wrap_err_with` loses the original error chain. `RocksDBBackend::open` returns `Result<_, Box<dyn std::error::Error + Send + Sync>>`, which already satisfies the `std::error::Error` bound required by `WrapErr`, so the intermediate `map_err(|err| eyre::eyre!("{err}"))` step — which stringifies the error and discards its chain — is unnecessary. Removing it lets eyre preserve the source error as a proper cause.

```suggestion
    let backend = Arc::new(
        RocksDBBackend::open(&data_dir)
            .wrap_err_with(|| format!("failed to open RocksDB at {}", data_dir.display()))?,
    );
```

Reviews (1): Last reviewed commit: "Improve main entrypoint error reporting" | Re-trigger Greptile

Comment thread bin/ethlambda/src/main.rs
Comment on lines +225 to +229
let backend = Arc::new(
RocksDBBackend::open(&data_dir)
.map_err(|err| eyre::eyre!("{err}"))
.wrap_err_with(|| format!("failed to open RocksDB at {}", data_dir.display()))?,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Redundant map_err before wrap_err_with loses the original error chain. RocksDBBackend::open returns Result<_, Box<dyn std::error::Error + Send + Sync>>, which already satisfies the std::error::Error bound required by WrapErr, so the intermediate map_err(|err| eyre::eyre!("{err}")) step — which stringifies the error and discards its chain — is unnecessary. Removing it lets eyre preserve the source error as a proper cause.

Suggested change
let backend = Arc::new(
RocksDBBackend::open(&data_dir)
.map_err(|err| eyre::eyre!("{err}"))
.wrap_err_with(|| format!("failed to open RocksDB at {}", data_dir.display()))?,
);
let backend = Arc::new(
RocksDBBackend::open(&data_dir)
.wrap_err_with(|| format!("failed to open RocksDB at {}", data_dir.display()))?,
);
Prompt To Fix With AI
This is a comment left during a code review.
Path: bin/ethlambda/src/main.rs
Line: 225-229

Comment:
Redundant `map_err` before `wrap_err_with` loses the original error chain. `RocksDBBackend::open` returns `Result<_, Box<dyn std::error::Error + Send + Sync>>`, which already satisfies the `std::error::Error` bound required by `WrapErr`, so the intermediate `map_err(|err| eyre::eyre!("{err}"))` step — which stringifies the error and discards its chain — is unnecessary. Removing it lets eyre preserve the source error as a proper cause.

```suggestion
    let backend = Arc::new(
        RocksDBBackend::open(&data_dir)
            .wrap_err_with(|| format!("failed to open RocksDB at {}", data_dir.display()))?,
    );
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@pablodeymo
pablodeymo merged commit 6de5447 into lambdaclass:main Jun 1, 2026
7 checks passed
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.

Improve error reporting in main entrypoint

2 participants