From 91dda2028b4a4d38dc6bf0dc67cec59189ef871f Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Tue, 10 Jan 2023 18:34:47 +0000 Subject: [PATCH] improve error handling for commands in singlePackage projects (#3243) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently in 'single package mode' the error message for missing turbo commands is a little misleading: ```bash turbo-single-test on  main [?] is 📦 v1.0.0 via  v19.4.0 ❯ ../turbo/target/debug/turbo ls ERROR run failed: task `ls` not found in turbo `pipeline` in "turbo.json". Are you sure you added it? Turbo error: task `ls` not found in turbo `pipeline` in "turbo ``` This PR makes a small change to the validation to respect the `singlePackage` option. ```bash turbo-single-test on  main [?] is 📦 v1.0.0 via  v19.4.0 ❯ ../turbo/target/debug/turbo ls ERROR run failed: task `ls` not found in `scripts` in "package.json" Turbo error: task `ls` not found in `scripts` in "package.json" ``` Co-authored-by: Thomas Knickman --- cli/internal/run/run.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/internal/run/run.go b/cli/internal/run/run.go index b70e4ef1eb2b0..741bd381327ba 100644 --- a/cli/internal/run/run.go +++ b/cli/internal/run/run.go @@ -201,7 +201,13 @@ func (r *run) run(ctx gocontext.Context, targets []string) error { pipeline := turboJSON.Pipeline if err := validateTasks(pipeline, targets); err != nil { - return err + location := "" + if r.opts.runOpts.singlePackage { + location = "in `scripts` in \"package.json\"" + } else { + location = "in `pipeline` in \"turbo.json\"" + } + return fmt.Errorf("%s %s. Are you sure you added it?", err, location) } scmInstance, err := scm.FromInRepo(r.base.RepoRoot) @@ -436,7 +442,7 @@ const ( func validateTasks(pipeline fs.Pipeline, tasks []string) error { for _, task := range tasks { if !pipeline.HasTask(task) { - return fmt.Errorf("task `%v` not found in turbo `pipeline` in \"turbo.json\". Are you sure you added it?", task) + return fmt.Errorf("task `%v` not found", task) } } return nil