From 682368bb8685638410404e56a1bbbc11f9d7d810 Mon Sep 17 00:00:00 2001 From: nicholaslyang Date: Fri, 8 Dec 2023 11:57:42 -0500 Subject: [PATCH] Fixing tests --- crates/turborepo-lib/src/cli/error.rs | 4 +++- crates/turborepo-lib/src/lib.rs | 11 ++++++++--- crates/turborepo-lib/src/shim.rs | 12 ++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/turborepo-lib/src/cli/error.rs b/crates/turborepo-lib/src/cli/error.rs index 3e83f976634f30..ec9b52ea1622f0 100644 --- a/crates/turborepo-lib/src/cli/error.rs +++ b/crates/turborepo-lib/src/cli/error.rs @@ -1,5 +1,6 @@ use std::backtrace; +use miette::Diagnostic; use thiserror::Error; use turborepo_repository::package_graph; @@ -10,7 +11,7 @@ use crate::{ run, }; -#[derive(Debug, Error)] +#[derive(Debug, Error, Diagnostic)] pub enum Error { #[error("No command specified")] NoCommand(#[backtrace] backtrace::Backtrace), @@ -41,6 +42,7 @@ pub enum Error { #[error(transparent)] PackageManager(#[from] turborepo_repository::package_manager::Error), #[error(transparent)] + #[diagnostic(transparent)] Run(#[from] run::Error), #[error(transparent)] SerdeJson(#[from] serde_json::Error), diff --git a/crates/turborepo-lib/src/lib.rs b/crates/turborepo-lib/src/lib.rs index 9aca66becb48b7..1602608dfeb850 100644 --- a/crates/turborepo-lib/src/lib.rs +++ b/crates/turborepo-lib/src/lib.rs @@ -32,8 +32,8 @@ mod tracing; pub use child::spawn_child; use miette::Report; -use crate::commands::CommandBase; pub use crate::{cli::Args, execution_state::ExecutionState}; +use crate::{commands::CommandBase, shim::Error}; /// The payload from running main, if the program can complete without using Go /// the Rust variant will be returned. If Go is needed then the execution state @@ -55,12 +55,17 @@ pub fn get_version() -> &'static str { pub fn main() -> Payload { match shim::run() { Ok(payload) => payload, + Err(err @ (Error::MultipleCwd(..) | Error::EmptyCwd { .. })) => { + println!("{:?}", Report::new(err)); + + Payload::Rust(Ok(1)) + } Err(err) => { // This raw print matches the Go behavior, once we no longer care // about matching formatting we should remove this. - println!("{:?}", Report::new(err)); + println!("Turbo error: {err}"); - Payload::Rust(Ok(1)) + Payload::Rust(Err(err)) } } } diff --git a/crates/turborepo-lib/src/shim.rs b/crates/turborepo-lib/src/shim.rs index 1df17208d8d4e4..cdf1e06873e735 100644 --- a/crates/turborepo-lib/src/shim.rs +++ b/crates/turborepo-lib/src/shim.rs @@ -63,6 +63,7 @@ pub enum Error { flag_range: SourceSpan, }, #[error(transparent)] + #[diagnostic(transparent)] Cli(#[from] cli::Error), #[error(transparent)] Inference(#[from] turborepo_repository::inference::Error), @@ -712,6 +713,17 @@ fn try_check_for_updates(args: &ShimArgs, current_version: &str) { pub fn run() -> Result { let args = ShimArgs::parse()?; let ui = args.ui(); + if ui.should_strip_ansi { + // Let's not crash just because we failed to set up the hook + let _ = miette::set_hook(Box::new(|_| { + Box::new( + miette::MietteHandlerOpts::new() + .color(false) + .unicode(false) + .build(), + ) + })); + } let subscriber = TurboSubscriber::new_with_verbosity(args.verbosity, &ui); debug!("Global turbo version: {}", get_version());