Improve main entrypoint error reporting - #404
Conversation
Greptile SummaryThis PR replaces all
Confidence Score: 4/5Safe 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 No files require special attention;
|
| 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]
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
| 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()))?, | ||
| ); |
There was a problem hiding this 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.
| 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!
🗒️ Description / Motivation
bin/ethlambdawitheyreerrors and contextual messages.unwrap/expect.What Changed
bin/ethlambda/src/main.rs.eyre::WrapErrusage around startup IO, parsing, tracing setup, RocksDB initialization, validator key loading, and swarm construction.eyre::Resultinstead of panicking or exiting internally.Correctness / Behavior Guarantees
eyreerrors with context.Tests Added / Run
cargo fmt --checkcargo check -p ethlambdacargo test -p ethlambdacargo test -p ethlambda-p2pRelated Issues / PRs
✅ Verification Checklist
cargo fmt --check— cleanmake fmt— not runmake lint(clippy with-D warnings) — not runcargo test --workspace --release— not run