From b1e94bdf2e043b75497fee9c0d7110294556028d Mon Sep 17 00:00:00 2001 From: f01dab1e Date: Wed, 2 Aug 2023 10:32:38 +0000 Subject: [PATCH 1/9] disable display location section --- crates/nargo_cli/src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/nargo_cli/src/main.rs b/crates/nargo_cli/src/main.rs index a73785c64c6..295ea32e208 100644 --- a/crates/nargo_cli/src/main.rs +++ b/crates/nargo_cli/src/main.rs @@ -5,11 +5,11 @@ use nargo_cli::cli::start_cli; 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. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.\nIf there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml") - .into_hooks(); - panic_hook.install(); + HookBuilder::default() + .display_env_section(false) + .display_location_section(cfg!(debug_assertions)) + .panic_section("This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.\nIf there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml") + .install()?; start_cli() } From 2a344cb8467a2020c8afd6c85f069594357a3c2b Mon Sep 17 00:00:00 2001 From: kek kek kek Date: Wed, 2 Aug 2023 11:15:36 -0700 Subject: [PATCH 2/9] disable display location section Co-authored-by: jfecher --- crates/nargo_cli/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/nargo_cli/src/main.rs b/crates/nargo_cli/src/main.rs index 6940f6ade7b..0e395d116d3 100644 --- a/crates/nargo_cli/src/main.rs +++ b/crates/nargo_cli/src/main.rs @@ -9,7 +9,7 @@ fn main() -> eyre::Result<()> { // Register a panic hook to display more readable panic messages to end-users HookBuilder::default() .display_env_section(false) - .display_location_section(cfg!(debug_assertions)) + .display_location_section(false) .panic_section(PANIC_MESSAGE) .install()?; From 90700d2ffb11cd0d973a27868a2b2fa05ec1963e Mon Sep 17 00:00:00 2001 From: f01dab1e Date: Tue, 15 Aug 2023 22:35:25 +0000 Subject: [PATCH 3/9] set RUST_LIB_BACKTRACE = 0 --- crates/nargo_cli/src/main.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/nargo_cli/src/main.rs b/crates/nargo_cli/src/main.rs index 0e395d116d3..fbd20f1917a 100644 --- a/crates/nargo_cli/src/main.rs +++ b/crates/nargo_cli/src/main.rs @@ -8,10 +8,14 @@ const PANIC_MESSAGE: &str = "This is a bug. We may have already fixed this in ne fn main() -> eyre::Result<()> { // Register a panic hook to display more readable panic messages to end-users HookBuilder::default() - .display_env_section(false) - .display_location_section(false) - .panic_section(PANIC_MESSAGE) - .install()?; + .display_env_section(false) + .display_location_section(false) + .panic_section(PANIC_MESSAGE) + .install()?; + + if std::env::var("RUST_LIB_BACKTRACE").is_err() { + std::env::set_var("RUST_LIB_BACKTRACE", "0"); + } start_cli() } From 4191ecd1a8e6523939ac810a9c5bde1af7af1af8 Mon Sep 17 00:00:00 2001 From: f01dab1e Date: Thu, 17 Aug 2023 12:27:30 +0000 Subject: [PATCH 4/9] use miette --- Cargo.lock | 112 +++++++++++++++++++++++++++++++- crates/nargo_cli/Cargo.toml | 4 +- crates/nargo_cli/src/cli/mod.rs | 10 +-- crates/nargo_cli/src/main.rs | 20 ++---- crates/nargo_cli/src/panic.rs | 80 +++++++++++++++++++++++ 5 files changed, 204 insertions(+), 22 deletions(-) create mode 100644 crates/nargo_cli/src/panic.rs diff --git a/Cargo.lock b/Cargo.lock index f513136caf3..7a7837ebaee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -407,6 +407,15 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "backtrace-ext" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50" +dependencies = [ + "backtrace", +] + [[package]] name = "barretenberg-sys" version = "0.2.0" @@ -1735,6 +1744,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is_ci" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" + [[package]] name = "iter-extended" version = "0.9.0" @@ -1934,6 +1949,38 @@ dependencies = [ "autocfg", ] +[[package]] +name = "miette" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" +dependencies = [ + "backtrace", + "backtrace-ext", + "is-terminal", + "miette-derive", + "once_cell", + "owo-colors", + "supports-color", + "supports-hyperlinks", + "supports-unicode", + "terminal_size", + "textwrap", + "thiserror", + "unicode-width", +] + +[[package]] +name = "miette-derive" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.26", +] + [[package]] name = "mime" version = "0.3.17" @@ -1999,15 +2046,17 @@ dependencies = [ "assert_cmd", "assert_fs", "async-lsp", + "backtrace", + "backtrace-ext", "build-data", "cfg-if", "clap", - "color-eyre", "const_format", "dirs", "fm", "hex", "iter-extended", + "miette", "nargo", "noir_lsp", "noirc_abi", @@ -3107,6 +3156,12 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +[[package]] +name = "smawk" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" + [[package]] name = "smol_str" version = "0.1.24" @@ -3192,6 +3247,34 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +[[package]] +name = "supports-color" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4950e7174bffabe99455511c39707310e7e9b440364a2fcb1cc21521be57b354" +dependencies = [ + "is-terminal", + "is_ci", +] + +[[package]] +name = "supports-hyperlinks" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84231692eb0d4d41e4cdd0cabfdd2e6cd9e255e65f80c9aa7c98dd502b4233d" +dependencies = [ + "is-terminal", +] + +[[package]] +name = "supports-unicode" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b6c2cb240ab5dd21ed4906895ee23fe5a48acdbd15a3ce388e7b62a9b66baf7" +dependencies = [ + "is-terminal", +] + [[package]] name = "syn" version = "1.0.109" @@ -3259,12 +3342,33 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "terminal_size" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "termtree" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" +[[package]] +name = "textwrap" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d" +dependencies = [ + "smawk", + "unicode-linebreak", + "unicode-width", +] + [[package]] name = "thiserror" version = "1.0.43" @@ -3509,6 +3613,12 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +[[package]] +name = "unicode-linebreak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" + [[package]] name = "unicode-normalization" version = "0.1.22" diff --git a/crates/nargo_cli/Cargo.toml b/crates/nargo_cli/Cargo.toml index a1c15997ef5..4aa0b1d8b5b 100644 --- a/crates/nargo_cli/Cargo.toml +++ b/crates/nargo_cli/Cargo.toml @@ -44,8 +44,10 @@ async-lsp = { version = "0.0.4", default-features = false, features = [ const_format = "0.2.30" hex = "0.4.2" termcolor = "1.1.2" -color-eyre = "0.6.2" tokio = { version = "1.0", features = ["io-std"] } +miette = { version = "5.10.0", features = ["fancy"] } +backtrace = "0.3.68" +backtrace-ext = "0.2.1" # Backends acvm-backend-barretenberg = { version = "0.10.0", default-features = false } diff --git a/crates/nargo_cli/src/cli/mod.rs b/crates/nargo_cli/src/cli/mod.rs index 9d494b21e6a..31acb5dd398 100644 --- a/crates/nargo_cli/src/cli/mod.rs +++ b/crates/nargo_cli/src/cli/mod.rs @@ -1,9 +1,8 @@ use clap::{Args, Parser, Subcommand}; use const_format::formatcp; +use miette::IntoDiagnostic; use std::path::PathBuf; -use color_eyre::eyre; - use crate::find_package_root; mod fs; @@ -61,12 +60,12 @@ enum NargoCommand { Lsp(lsp_cmd::LspCommand), } -pub fn start_cli() -> eyre::Result<()> { +pub fn start_cli() -> miette::Result<()> { let NargoCli { command, mut config } = NargoCli::parse(); // Search through parent directories to find package root if necessary. if !matches!(command, NargoCommand::New(_) | NargoCommand::Init(_) | NargoCommand::Lsp(_)) { - config.program_dir = find_package_root(&config.program_dir)?; + config.program_dir = find_package_root(&config.program_dir).into_diagnostic()?; } let backend = crate::backends::ConcreteBackend::default(); @@ -83,7 +82,8 @@ pub fn start_cli() -> eyre::Result<()> { NargoCommand::Info(args) => info_cmd::run(&backend, args, config), NargoCommand::CodegenVerifier(args) => codegen_verifier_cmd::run(&backend, args, config), NargoCommand::Lsp(args) => lsp_cmd::run(&backend, args, config), - }?; + } + .into_diagnostic()?; Ok(()) } diff --git a/crates/nargo_cli/src/main.rs b/crates/nargo_cli/src/main.rs index fbd20f1917a..a30fd99b00c 100644 --- a/crates/nargo_cli/src/main.rs +++ b/crates/nargo_cli/src/main.rs @@ -1,21 +1,11 @@ #![forbid(unsafe_code)] -use color_eyre::{config::HookBuilder, eyre}; -use nargo_cli::cli::start_cli; +mod panic; -const PANIC_MESSAGE: &str = "This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.\nIf there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml"; +fn main() { + panic::set_hook(); -fn main() -> eyre::Result<()> { - // Register a panic hook to display more readable panic messages to end-users - HookBuilder::default() - .display_env_section(false) - .display_location_section(false) - .panic_section(PANIC_MESSAGE) - .install()?; - - if std::env::var("RUST_LIB_BACKTRACE").is_err() { - std::env::set_var("RUST_LIB_BACKTRACE", "0"); + if let Err(report) = nargo_cli::cli::start_cli() { + println!("{report}"); } - - start_cli() } diff --git a/crates/nargo_cli/src/panic.rs b/crates/nargo_cli/src/panic.rs new file mode 100644 index 00000000000..e336b27ec59 --- /dev/null +++ b/crates/nargo_cli/src/panic.rs @@ -0,0 +1,80 @@ +// based on this code: https://github.com/zkat/miette/blob/main/src/panic.rs + +use backtrace::Backtrace; +use miette::{Diagnostic, WrapErr}; +use thiserror::Error; + +const PANIC_MESSAGE: &str = "This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.\nIf there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml"; + +pub fn set_hook() { + std::panic::set_hook(Box::new(move |info| { + let mut report: miette::Result<()> = Err(Panic.into()); + if let Some(loc) = info.location() { + report = report + .with_context(|| format!("at {}:{}:{}", loc.file(), loc.line(), loc.column())); + } + if let Err(err) = report.with_context(|| PANIC_MESSAGE.to_string()) { + eprintln!("{err:?}"); + } + })); +} + +#[derive(Debug, Error, Diagnostic)] +#[error("{0}{}", Panic::backtrace())] +#[diagnostic()] +struct Panic; + +impl Panic { + fn backtrace() -> String { + use std::fmt::Write; + if let Ok(var) = std::env::var("RUST_BACKTRACE") { + if !var.is_empty() && var != "0" { + const HEX_WIDTH: usize = std::mem::size_of::() + 2; + // Padding for next lines after frame's address + const NEXT_SYMBOL_PADDING: usize = HEX_WIDTH + 6; + let mut backtrace = String::new(); + let trace = Backtrace::new(); + let frames = backtrace_ext::short_frames_strict(&trace).enumerate(); + for (idx, (frame, sub_frames)) in frames { + let ip = frame.ip(); + let _ = write!(backtrace, "\n{:4}: {:2$?}", idx, ip, HEX_WIDTH); + + let symbols = frame.symbols(); + if symbols.is_empty() { + let _ = write!(backtrace, " - "); + continue; + } + + for (idx, symbol) in symbols[sub_frames].iter().enumerate() { + // Print symbols from this address, + // if there are several addresses + // we need to put it on next line + if idx != 0 { + let _ = write!(backtrace, "\n{:1$}", "", NEXT_SYMBOL_PADDING); + } + + if let Some(name) = symbol.name() { + let _ = write!(backtrace, " - {}", name); + } else { + let _ = write!(backtrace, " - "); + } + + // See if there is debug information with file name and line + if let (Some(file), Some(line)) = (symbol.filename(), symbol.lineno()) { + let _ = write!( + backtrace, + "\n{:3$}at {}:{}", + "", + file.display(), + line, + NEXT_SYMBOL_PADDING + ); + } + } + } + return backtrace; + } + } + "".into() + } +} From ed7d7374d1cc7b732155a1b1f5c531db514f4e90 Mon Sep 17 00:00:00 2001 From: f01dab1e Date: Thu, 17 Aug 2023 17:25:04 +0000 Subject: [PATCH 5/9] `std::process::exit(1)` --- crates/nargo_cli/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/nargo_cli/src/main.rs b/crates/nargo_cli/src/main.rs index a30fd99b00c..f083ec9341c 100644 --- a/crates/nargo_cli/src/main.rs +++ b/crates/nargo_cli/src/main.rs @@ -6,6 +6,7 @@ fn main() { panic::set_hook(); if let Err(report) = nargo_cli::cli::start_cli() { - println!("{report}"); + eprintln!("{report}"); + std::process::exit(1); } } From 2afed67fcf9095e7726cf55c19d2d22e60d54a47 Mon Sep 17 00:00:00 2001 From: f01dab1e Date: Thu, 17 Aug 2023 17:48:58 +0000 Subject: [PATCH 6/9] fix comp errors --- crates/nargo_cli/src/cli/mod.rs | 2 -- crates/nargo_cli/src/main.rs | 1 + crates/nargo_cli/src/panic.rs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/nargo_cli/src/cli/mod.rs b/crates/nargo_cli/src/cli/mod.rs index 6458fc9a161..2fc1ddd0de5 100644 --- a/crates/nargo_cli/src/cli/mod.rs +++ b/crates/nargo_cli/src/cli/mod.rs @@ -4,8 +4,6 @@ use miette::IntoDiagnostic; use nargo_toml::find_package_root; use std::path::PathBuf; -use crate::find_package_root; - mod fs; mod check_cmd; diff --git a/crates/nargo_cli/src/main.rs b/crates/nargo_cli/src/main.rs index 0031bdcc353..b30c660ae31 100644 --- a/crates/nargo_cli/src/main.rs +++ b/crates/nargo_cli/src/main.rs @@ -10,6 +10,7 @@ mod backends; mod cli; mod errors; +mod panic; fn main() { panic::set_hook(); diff --git a/crates/nargo_cli/src/panic.rs b/crates/nargo_cli/src/panic.rs index e336b27ec59..f316568e298 100644 --- a/crates/nargo_cli/src/panic.rs +++ b/crates/nargo_cli/src/panic.rs @@ -6,7 +6,7 @@ use thiserror::Error; const PANIC_MESSAGE: &str = "This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.\nIf there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml"; -pub fn set_hook() { +pub(crate) fn set_hook() { std::panic::set_hook(Box::new(move |info| { let mut report: miette::Result<()> = Err(Panic.into()); if let Some(loc) = info.location() { From 427d8f5efcdaf2e6f0a3be6f2ae050edc917830e Mon Sep 17 00:00:00 2001 From: f01dab1e Date: Thu, 17 Aug 2023 18:31:45 +0000 Subject: [PATCH 7/9] use color-eyre crate for panic handling --- Cargo.lock | 3 +- crates/nargo_cli/Cargo.toml | 3 +- crates/nargo_cli/src/main.rs | 9 +++- crates/nargo_cli/src/panic.rs | 80 ----------------------------------- 4 files changed, 9 insertions(+), 86 deletions(-) delete mode 100644 crates/nargo_cli/src/panic.rs diff --git a/Cargo.lock b/Cargo.lock index 129215c283f..edf2df5bdec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2228,10 +2228,9 @@ dependencies = [ "assert_cmd", "assert_fs", "async-lsp", - "backtrace", - "backtrace-ext", "build-data", "clap", + "color-eyre", "const_format", "criterion", "dirs", diff --git a/crates/nargo_cli/Cargo.toml b/crates/nargo_cli/Cargo.toml index 1a235a69e00..9efd203e7f5 100644 --- a/crates/nargo_cli/Cargo.toml +++ b/crates/nargo_cli/Cargo.toml @@ -46,8 +46,7 @@ hex = "0.4.2" termcolor = "1.1.2" tokio = { version = "1.0", features = ["io-std"] } miette = { version = "5.10.0", features = ["fancy"] } -backtrace = "0.3.68" -backtrace-ext = "0.2.1" +color-eyre = "0.6.2" tokio-util = { version = "0.7.8", features = ["compat"] } # Backends diff --git a/crates/nargo_cli/src/main.rs b/crates/nargo_cli/src/main.rs index b30c660ae31..40cb0856c71 100644 --- a/crates/nargo_cli/src/main.rs +++ b/crates/nargo_cli/src/main.rs @@ -7,13 +7,18 @@ //! This name was used because it sounds like `cargo` and //! Noir Package Manager abbreviated is npm, which is already taken. +use color_eyre::config::HookBuilder; + mod backends; mod cli; mod errors; -mod panic; + +const PANIC_MESSAGE: &str = "This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.\nIf there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml"; fn main() { - panic::set_hook(); + let (panic_hook, _) = + HookBuilder::default().display_env_section(false).panic_section(PANIC_MESSAGE).into_hooks(); + panic_hook.install(); if let Err(report) = cli::start_cli() { eprintln!("{report}"); diff --git a/crates/nargo_cli/src/panic.rs b/crates/nargo_cli/src/panic.rs deleted file mode 100644 index f316568e298..00000000000 --- a/crates/nargo_cli/src/panic.rs +++ /dev/null @@ -1,80 +0,0 @@ -// based on this code: https://github.com/zkat/miette/blob/main/src/panic.rs - -use backtrace::Backtrace; -use miette::{Diagnostic, WrapErr}; -use thiserror::Error; - -const PANIC_MESSAGE: &str = "This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.\nIf there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml"; - -pub(crate) fn set_hook() { - std::panic::set_hook(Box::new(move |info| { - let mut report: miette::Result<()> = Err(Panic.into()); - if let Some(loc) = info.location() { - report = report - .with_context(|| format!("at {}:{}:{}", loc.file(), loc.line(), loc.column())); - } - if let Err(err) = report.with_context(|| PANIC_MESSAGE.to_string()) { - eprintln!("{err:?}"); - } - })); -} - -#[derive(Debug, Error, Diagnostic)] -#[error("{0}{}", Panic::backtrace())] -#[diagnostic()] -struct Panic; - -impl Panic { - fn backtrace() -> String { - use std::fmt::Write; - if let Ok(var) = std::env::var("RUST_BACKTRACE") { - if !var.is_empty() && var != "0" { - const HEX_WIDTH: usize = std::mem::size_of::() + 2; - // Padding for next lines after frame's address - const NEXT_SYMBOL_PADDING: usize = HEX_WIDTH + 6; - let mut backtrace = String::new(); - let trace = Backtrace::new(); - let frames = backtrace_ext::short_frames_strict(&trace).enumerate(); - for (idx, (frame, sub_frames)) in frames { - let ip = frame.ip(); - let _ = write!(backtrace, "\n{:4}: {:2$?}", idx, ip, HEX_WIDTH); - - let symbols = frame.symbols(); - if symbols.is_empty() { - let _ = write!(backtrace, " - "); - continue; - } - - for (idx, symbol) in symbols[sub_frames].iter().enumerate() { - // Print symbols from this address, - // if there are several addresses - // we need to put it on next line - if idx != 0 { - let _ = write!(backtrace, "\n{:1$}", "", NEXT_SYMBOL_PADDING); - } - - if let Some(name) = symbol.name() { - let _ = write!(backtrace, " - {}", name); - } else { - let _ = write!(backtrace, " - "); - } - - // See if there is debug information with file name and line - if let (Some(file), Some(line)) = (symbol.filename(), symbol.lineno()) { - let _ = write!( - backtrace, - "\n{:3$}at {}:{}", - "", - file.display(), - line, - NEXT_SYMBOL_PADDING - ); - } - } - } - return backtrace; - } - } - "".into() - } -} From b7c50de29d3a60ef53491357c5ca97a2aba84c49 Mon Sep 17 00:00:00 2001 From: f01dab1e Date: Thu, 17 Aug 2023 20:56:39 +0000 Subject: [PATCH 8/9] remove miette --- Cargo.lock | 113 +------------------------------- crates/nargo_cli/Cargo.toml | 3 +- crates/nargo_cli/src/cli/mod.rs | 9 ++- 3 files changed, 7 insertions(+), 118 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index edf2df5bdec..3a0a73ff69d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -420,15 +420,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "backtrace-ext" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50" -dependencies = [ - "backtrace", -] - [[package]] name = "barretenberg-sys" version = "0.2.0" @@ -1921,12 +1912,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "is_ci" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" - [[package]] name = "iter-extended" version = "0.10.3" @@ -2130,38 +2115,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "miette" -version = "5.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" -dependencies = [ - "backtrace", - "backtrace-ext", - "is-terminal", - "miette-derive", - "once_cell", - "owo-colors", - "supports-color", - "supports-hyperlinks", - "supports-unicode", - "terminal_size", - "textwrap", - "thiserror", - "unicode-width", -] - -[[package]] -name = "miette-derive" -version = "5.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.29", -] - [[package]] name = "mime" version = "0.3.17" @@ -2238,7 +2191,6 @@ dependencies = [ "hex", "iai", "iter-extended", - "miette", "nargo", "nargo_toml", "noir_lsp", @@ -3477,12 +3429,6 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" -[[package]] -name = "smawk" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" - [[package]] name = "smol_str" version = "0.1.24" @@ -3590,34 +3536,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" -[[package]] -name = "supports-color" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4950e7174bffabe99455511c39707310e7e9b440364a2fcb1cc21521be57b354" -dependencies = [ - "is-terminal", - "is_ci", -] - -[[package]] -name = "supports-hyperlinks" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f84231692eb0d4d41e4cdd0cabfdd2e6cd9e255e65f80c9aa7c98dd502b4233d" -dependencies = [ - "is-terminal", -] - -[[package]] -name = "supports-unicode" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b6c2cb240ab5dd21ed4906895ee23fe5a48acdbd15a3ce388e7b62a9b66baf7" -dependencies = [ - "is-terminal", -] - [[package]] name = "symbolic-common" version = "12.3.0" @@ -3718,33 +3636,12 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "terminal_size" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "termtree" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" -[[package]] -name = "textwrap" -version = "0.15.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d" -dependencies = [ - "smawk", - "unicode-linebreak", - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.47" @@ -3999,12 +3896,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" -[[package]] -name = "unicode-linebreak" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" - [[package]] name = "unicode-normalization" version = "0.1.22" @@ -4655,9 +4546,9 @@ checksum = "b6ade45bc8bf02ae2aa34a9d54ba660a1a58204da34ba793c00d83ca3730b5f1" [[package]] name = "winnow" -version = "0.5.12" +version = "0.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83817bbecf72c73bad717ee86820ebf286203d2e04c3951f3cd538869c897364" +checksum = "d09770118a7eb1ccaf4a594a221334119a44a814fcb0d31c5b85e83e97227a97" dependencies = [ "memchr", ] diff --git a/crates/nargo_cli/Cargo.toml b/crates/nargo_cli/Cargo.toml index 9efd203e7f5..13205c00022 100644 --- a/crates/nargo_cli/Cargo.toml +++ b/crates/nargo_cli/Cargo.toml @@ -44,9 +44,8 @@ async-lsp = { version = "0.0.5", default-features = false, features = [ const_format = "0.2.30" hex = "0.4.2" termcolor = "1.1.2" -tokio = { version = "1.0", features = ["io-std"] } -miette = { version = "5.10.0", features = ["fancy"] } color-eyre = "0.6.2" +tokio = { version = "1.0", features = ["io-std"] } tokio-util = { version = "0.7.8", features = ["compat"] } # Backends diff --git a/crates/nargo_cli/src/cli/mod.rs b/crates/nargo_cli/src/cli/mod.rs index 2fc1ddd0de5..f95b575d3df 100644 --- a/crates/nargo_cli/src/cli/mod.rs +++ b/crates/nargo_cli/src/cli/mod.rs @@ -1,6 +1,6 @@ use clap::{Args, Parser, Subcommand}; +use color_eyre::eyre; use const_format::formatcp; -use miette::IntoDiagnostic; use nargo_toml::find_package_root; use std::path::PathBuf; @@ -60,7 +60,7 @@ enum NargoCommand { Lsp(lsp_cmd::LspCommand), } -pub(crate) fn start_cli() -> miette::Result<()> { +pub(crate) fn start_cli() -> eyre::Result<()> { let NargoCli { command, mut config } = NargoCli::parse(); // If the provided `program_dir` is relative, make it absolute by joining it to the current directory. @@ -70,7 +70,7 @@ pub(crate) fn start_cli() -> miette::Result<()> { // Search through parent directories to find package root if necessary. if !matches!(command, NargoCommand::New(_) | NargoCommand::Init(_) | NargoCommand::Lsp(_)) { - config.program_dir = find_package_root(&config.program_dir).into_diagnostic()?; + config.program_dir = find_package_root(&config.program_dir)?; } let backend = crate::backends::ConcreteBackend::default(); @@ -87,8 +87,7 @@ pub(crate) fn start_cli() -> miette::Result<()> { NargoCommand::Info(args) => info_cmd::run(&backend, args, config), NargoCommand::CodegenVerifier(args) => codegen_verifier_cmd::run(&backend, args, config), NargoCommand::Lsp(args) => lsp_cmd::run(&backend, args, config), - } - .into_diagnostic()?; + }?; Ok(()) } From 1450dd24e8c58bf745b37b1f5bfa6208fc8dd825 Mon Sep 17 00:00:00 2001 From: f01dab1e Date: Mon, 28 Aug 2023 17:59:35 +0000 Subject: [PATCH 9/9] smol diff --- crates/nargo_cli/src/cli/mod.rs | 3 ++- crates/nargo_cli/src/main.rs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/nargo_cli/src/cli/mod.rs b/crates/nargo_cli/src/cli/mod.rs index f95b575d3df..2603db3ce19 100644 --- a/crates/nargo_cli/src/cli/mod.rs +++ b/crates/nargo_cli/src/cli/mod.rs @@ -1,9 +1,10 @@ use clap::{Args, Parser, Subcommand}; -use color_eyre::eyre; use const_format::formatcp; use nargo_toml::find_package_root; use std::path::PathBuf; +use color_eyre::eyre; + mod fs; mod check_cmd; diff --git a/crates/nargo_cli/src/main.rs b/crates/nargo_cli/src/main.rs index 40cb0856c71..b0a0a98f3f7 100644 --- a/crates/nargo_cli/src/main.rs +++ b/crates/nargo_cli/src/main.rs @@ -7,15 +7,16 @@ //! This name was used because it sounds like `cargo` and //! Noir Package Manager abbreviated is npm, which is already taken. -use color_eyre::config::HookBuilder; - mod backends; mod cli; mod errors; +use color_eyre::config::HookBuilder; + const PANIC_MESSAGE: &str = "This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.\nIf there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml"; fn main() { + // Register a panic hook to display more readable panic messages to end-users let (panic_hook, _) = HookBuilder::default().display_env_section(false).panic_section(PANIC_MESSAGE).into_hooks(); panic_hook.install();