Skip to content

Commit

Permalink
Merge 941ab9a into 1fa0fe1
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Dec 8, 2023
2 parents 1fa0fe1 + 941ab9a commit 7c45361
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 68 deletions.
70 changes: 59 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ lto = "off"
async-recursion = "1.0.2"
# Keep consistent with preset_env_base through swc_core
browserslist-rs = { version = "0.13.0" }

miette = { version = "5.10.0", features = ["fancy"] }
mdxjs = "0.1.20"
modularize_imports = { version = "0.62.0" }
styled_components = { version = "0.90.0" }
Expand Down
2 changes: 0 additions & 2 deletions crates/turborepo-api-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ pub enum Error {
status: CachingStatus,
message: String,
},
#[error("cache miss")]
CacheMiss,
}

pub type Result<T> = std::result::Result<T, Error>;
2 changes: 2 additions & 0 deletions crates/turborepo-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ tonic-reflection = { version = "0.6.0", optional = true }
tower = "0.4.13"
turborepo-analytics = { path = "../turborepo-analytics" }
turborepo-auth = { path = "../turborepo-auth" }

turborepo-fs = { path = "../turborepo-fs" }
turborepo-graph-utils = { path = "../turborepo-graph-utils" }
turborepo-repository = { path = "../turborepo-repository" }
Expand All @@ -99,6 +100,7 @@ globwalk = { version = "0.1.0", path = "../turborepo-globwalk" }
go-parse-duration = "0.1.1"
is-terminal = "0.4.7"
lazy-regex = "2.5.0"
miette = { workspace = true, features = ["fancy"] }
node-semver = "2.1.0"
num_cpus = "1.15.0"
owo-colors.workspace = true
Expand Down
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
4 changes: 3 additions & 1 deletion crates/turborepo-lib/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use std::{

pub use builder::{EngineBuilder, Error as BuilderError};
pub use execute::{ExecuteError, ExecutionOptions, Message, StopExecution};
use miette::Diagnostic;
use petgraph::Graph;
use thiserror::Error;
use turborepo_repository::package_graph::{PackageGraph, WorkspaceName};

use crate::{run::task_id::TaskId, task_graph::TaskDefinition};
Expand Down Expand Up @@ -226,7 +228,7 @@ impl Engine<Built> {
}
}

#[derive(Debug, thiserror::Error)]
#[derive(Debug, Error, Diagnostic)]
pub enum ValidateError {
#[error("Cannot find task definition for {task_id} in package {package_name}")]
MissingTask {
Expand Down
9 changes: 8 additions & 1 deletion crates/turborepo-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ mod task_hash;
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 @@ -56,10 +57,16 @@ pub fn main() -> Payload {
Ok(payload) => payload,
// We don't need to print "Turbo error" for Run errors
Err(err @ shim::Error::Cli(cli::Error::Run(_))) => Payload::Rust(Err(err)),
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!("Turbo error: {err}");

Payload::Rust(Err(err))
}
}
Expand Down
10 changes: 7 additions & 3 deletions crates/turborepo-lib/src/run/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use miette::Diagnostic;
use thiserror::Error;
use turborepo_repository::package_graph;

Expand All @@ -8,12 +9,15 @@ use crate::{
task_graph, task_hash,
};

#[derive(Debug, Error)]
#[derive(Debug, Error, Diagnostic)]
pub enum Error {
#[error("error preparing engine: Invalid persistent task configuration:")]
EngineValidation {
#[related]
validation_errors: Vec<engine::ValidateError>,
},
#[error(transparent)]
Graph(#[from] graph_visualizer::Error),
#[error("error preparing engine: Invalid persistent task configuration:\n{0}")]
EngineValidation(String),
#[error(transparent)]
Builder(#[from] engine::BuilderError),
#[error(transparent)]
Expand Down
11 changes: 2 additions & 9 deletions crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::{

pub use cache::{RunCache, TaskCache};
use chrono::{DateTime, Local};
use itertools::Itertools;
use rayon::iter::ParallelBridge;
use tracing::debug;
use turborepo_analytics::{start_analytics, AnalyticsHandle, AnalyticsSender};
Expand Down Expand Up @@ -668,14 +667,8 @@ impl<'a> Run<'a> {
if !opts.run_opts.parallel {
engine
.validate(pkg_dep_graph, opts.run_opts.concurrency)
.map_err(|errors| {
Error::EngineValidation(
errors
.into_iter()
.map(|e| e.to_string())
.sorted()
.join("\n"),
)
.map_err(|errors| Error::EngineValidation {
validation_errors: errors,
})?;
}

Expand Down
Loading

0 comments on commit 7c45361

Please sign in to comment.