From aef87757f4f10a9925b7a65f48bc863677bd3a7a Mon Sep 17 00:00:00 2001 From: Nicholas Yang Date: Tue, 28 May 2024 15:53:26 -0400 Subject: [PATCH] chore(turborepo): Improve pipeline error message (#8231) ### Description Made a nicer error message for having a `pipeline` key instead of `tasks`. ### Testing Instructions --------- Co-authored-by: Anthony Shew --- crates/turborepo-lib/src/config.rs | 8 ++++++++ crates/turborepo-lib/src/turbo_json/mod.rs | 7 +++++++ crates/turborepo-lib/src/turbo_json/parser.rs | 6 ++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/turborepo-lib/src/config.rs b/crates/turborepo-lib/src/config.rs index 5837ea0e0943b..09f351636d9e6 100644 --- a/crates/turborepo-lib/src/config.rs +++ b/crates/turborepo-lib/src/config.rs @@ -132,6 +132,14 @@ pub enum Error { #[source_code] text: NamedSource, }, + #[error("found `pipeline` field instead of `tasks`")] + #[diagnostic(help("Deprecated in 2.0: `pipeline` has been renamed to `tasks`"))] + PipelineField { + #[label("rename `pipeline` field to `tasks`")] + span: Option, + #[source_code] + text: NamedSource, + }, #[error("Failed to create APIClient: {0}")] ApiClient(#[source] turborepo_api_client::Error), #[error("{0} is not UTF8.")] diff --git a/crates/turborepo-lib/src/turbo_json/mod.rs b/crates/turborepo-lib/src/turbo_json/mod.rs index 2b578f0bd03e7..3df788a9f5879 100644 --- a/crates/turborepo-lib/src/turbo_json/mod.rs +++ b/crates/turborepo-lib/src/turbo_json/mod.rs @@ -117,6 +117,9 @@ pub struct RawTurboJson { // and cache behavior on a per task or per package-task basis. #[serde(skip_serializing_if = "Option::is_none")] pub tasks: Option, + + #[serde(skip_serializing)] + pub pipeline: Option>, // Configuration options when interfacing with the remote cache #[serde(skip_serializing_if = "Option::is_none")] pub(crate) remote_cache: Option, @@ -432,6 +435,10 @@ impl TryFrom for TurboJson { type Error = Error; fn try_from(raw_turbo: RawTurboJson) -> Result { + if let Some(pipeline) = raw_turbo.pipeline { + let (span, text) = pipeline.span_and_text("turbo.json"); + return Err(Error::PipelineField { span, text }); + } let mut global_env = HashSet::new(); let mut global_file_dependencies = HashSet::new(); diff --git a/crates/turborepo-lib/src/turbo_json/parser.rs b/crates/turborepo-lib/src/turbo_json/parser.rs index 532b76e74f44f..47e16702a537c 100644 --- a/crates/turborepo-lib/src/turbo_json/parser.rs +++ b/crates/turborepo-lib/src/turbo_json/parser.rs @@ -147,7 +147,8 @@ impl WithMetadata for RawTurboJson { self.global_dependencies.add_text(text.clone()); self.global_env.add_text(text.clone()); self.global_pass_through_env.add_text(text.clone()); - self.tasks.add_text(text); + self.tasks.add_text(text.clone()); + self.pipeline.add_text(text); } fn add_path(&mut self, path: Arc) { @@ -156,7 +157,8 @@ impl WithMetadata for RawTurboJson { self.global_dependencies.add_path(path.clone()); self.global_env.add_path(path.clone()); self.global_pass_through_env.add_path(path.clone()); - self.tasks.add_path(path); + self.tasks.add_path(path.clone()); + self.pipeline.add_path(path); } }