Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Dec 8, 2023
1 parent 84c83b9 commit 682368b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 3 additions & 1 deletion crates/turborepo-lib/src/cli/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::backtrace;

use miette::Diagnostic;
use thiserror::Error;
use turborepo_repository::package_graph;

Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
11 changes: 8 additions & 3 deletions crates/turborepo-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}
}
}
12 changes: 12 additions & 0 deletions crates/turborepo-lib/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -712,6 +713,17 @@ fn try_check_for_updates(args: &ShimArgs, current_version: &str) {
pub fn run() -> Result<Payload, Error> {
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());
Expand Down

0 comments on commit 682368b

Please sign in to comment.