Skip to content

Commit

Permalink
chore(nargo): report bubbled up errors using eyre (#907)
Browse files Browse the repository at this point in the history
* chore(nargo): report errors using anyhow

* chore: replace anyhow with eyre
  • Loading branch information
TomAFrench authored Feb 28, 2023
1 parent 007ab75 commit e87ce66
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
13 changes: 7 additions & 6 deletions crates/nargo/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use noirc_driver::Driver;
use noirc_frontend::graph::{CrateName, CrateType};
use std::path::{Path, PathBuf};

use color_eyre::eyre;

mod fs;

mod check_cmd;
Expand Down Expand Up @@ -55,10 +57,10 @@ enum NargoCommand {
Gates(gates_cmd::GatesCommand),
}

pub fn start_cli() {
pub fn start_cli() -> eyre::Result<()> {
let matches = NargoCli::parse();

let result = match matches.command {
match matches.command {
NargoCommand::New(args) => new_cmd::run(args, matches.config),
NargoCommand::Check(args) => check_cmd::run(args, matches.config),
NargoCommand::Compile(args) => compile_cmd::run(args, matches.config),
Expand All @@ -68,10 +70,9 @@ pub fn start_cli() {
NargoCommand::Test(args) => test_cmd::run(args, matches.config),
NargoCommand::Gates(args) => gates_cmd::run(args, matches.config),
NargoCommand::Contract(args) => contract_cmd::run(args, matches.config),
};
if let Err(err) = result {
err.write()
}
}?;

Ok(())
}

// helper function which tests noir programs by trying to generate a proof and verify it
Expand Down
15 changes: 1 addition & 14 deletions crates/nargo/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use acvm::OpcodeResolutionError;
use hex::FromHexError;
use noirc_abi::errors::{AbiError, InputParserError};
use std::{io::Write, path::PathBuf};
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
use std::path::PathBuf;
use thiserror::Error;

#[derive(Debug, Error)]
Expand Down Expand Up @@ -31,18 +30,6 @@ impl From<OpcodeResolutionError> for CliError {
}
}

impl CliError {
pub(crate) fn write(&self) -> ! {
let mut stderr = StandardStream::stderr(ColorChoice::Always);
stderr
.set_color(ColorSpec::new().set_fg(Some(Color::Red)))
.expect("cannot set color for stderr in StandardStream");
writeln!(&mut stderr, "{self}").expect("cannot write to stderr");

std::process::exit(1)
}
}

impl From<InputParserError> for CliError {
fn from(error: InputParserError) -> Self {
CliError::Generic(error.to_string())
Expand Down
6 changes: 3 additions & 3 deletions crates/nargo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#![forbid(unsafe_code)]

use color_eyre::config::HookBuilder;
use color_eyre::{config::HookBuilder, eyre};
use nargo::cli::start_cli;

fn main() {
fn main() -> eyre::Result<()> {
// Register a panic hook to display more readable panic messages to end-users
let (panic_hook, _) = HookBuilder::default()
.display_env_section(false)
.panic_section("This is a bug. Consider opening an issue at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.md")
.into_hooks();
panic_hook.install();

start_cli();
start_cli()
}

0 comments on commit e87ce66

Please sign in to comment.