Skip to content

Commit

Permalink
improve error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
dknopik committed Oct 10, 2024
1 parent e3a605e commit ab540dc
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 6 deletions.
209 changes: 209 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ path = "ethshadow.rs"

[dependencies]
ethshadow = { path = "lib" }
clap = { version = "4.5", features = ["cargo"] }
clap = { version = "4.5", features = ["cargo"] }
color-eyre = "0.6"
11 changes: 6 additions & 5 deletions ethshadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
//! ```

use clap::{arg, command, value_parser};
use color_eyre::Result;
use ethshadow::generate;
use std::env;
use std::error::Error;
use std::fs::File;
use std::os::unix::prelude::CommandExt;
use std::path::PathBuf;
use color_eyre::eyre::WrapErr;

fn main() -> Result<(), Box<dyn Error>> {
fn main() -> Result<()> {
let mut matches = command!() // requires `cargo` feature
.bin_name("ethshadow")
.arg(arg!(dir: -d [DIR] "Output directory for ethshadow and Shadow")
Expand All @@ -32,16 +33,16 @@ fn main() -> Result<(), Box<dyn Error>> {
.expect("there is a default in place");
let config = matches.get_one::<PathBuf>("config").expect("required arg");

let config = File::open(config)?;
let config = File::open(config).wrap_err("Unable to read the config")?;

let mut invocation = generate(config, dir)?;
let mut invocation = generate(config, dir).wrap_err("Failed to generate data directory")?;

if !matches.get_flag("genonly") {
if let Some(user_args) = matches.get_many::<String>("shadow_cli") {
invocation.with_user_args(user_args);
}
// if exec() returns, the call failed!
Err(invocation.command().exec().into())
Err(invocation.command().exec()).wrap_err("Failed to invoke Shadow")
} else {
Ok(())
}
Expand Down

0 comments on commit ab540dc

Please sign in to comment.