Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(nargo): report bubbled up errors using eyre #907

Merged
merged 3 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_abi::InputMap;
use noirc_driver::Driver;
use noirc_frontend::graph::{CrateName, CrateType};
use std::path::{Path, PathBuf};

use color_eyre::eyre;
extern crate tempdir;
use tempdir::TempDir;

Expand Down Expand Up @@ -58,10 +60,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 @@ -71,10 +73,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 @@ -35,18 +34,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)
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
}
}

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()
}