Skip to content

Commit

Permalink
Error if none of the tasks passed to CLI were found (#3828)
Browse files Browse the repository at this point in the history
Previously, a `validate` method asserted that tasks passed to the
CLI exist. We removed this validation for the purpose of lazily
loading turbo.jsons. Bringing back this feature here.
  • Loading branch information
mehulkar committed Feb 16, 2023
1 parent a18af02 commit 0186f61
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
12 changes: 4 additions & 8 deletions cli/integration_tests/basic_monorepo/dry_run.t
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,8 @@ Check my-app#build output
}
}

$ Non-existent tasks don't throw an error
Tasks that don't exist throw an error
$ ${TURBO} run doesnotexist --dry=json
{
"packages": [
"my-app",
"util"
],
"tasks": []
}
ERROR run failed: error preparing engine: Could not find the following tasks in project: doesnotexist
Turbo error: error preparing engine: Could not find the following tasks in project: doesnotexist
[1]
27 changes: 16 additions & 11 deletions cli/integration_tests/basic_monorepo/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ Setup
$ . ${TESTDIR}/../setup.sh
$ . ${TESTDIR}/setup.sh $(pwd)

$ running non-existent tasks works
# Running non-existent tasks errors
$ ${TURBO} run doesnotexist
\xe2\x80\xa2 Packages in scope: my-app, util (esc)
\xe2\x80\xa2 Running doesnotexist in 2 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)

No tasks were executed as part of this run.

Tasks: 0 successful, 0 total
Cached: 0 cached, 0 total
Time:\s*[\.0-9]+m?s (re)

ERROR run failed: error preparing engine: Could not find the following tasks in project: doesnotexist
Turbo error: error preparing engine: Could not find the following tasks in project: doesnotexist
[1]

# Multiple non-existent tasks also error
$ ${TURBO} run doesnotexist alsono
ERROR run failed: error preparing engine: Could not find the following tasks in project: alsono, doesnotexist
Turbo error: error preparing engine: Could not find the following tasks in project: alsono, doesnotexist
[1]

# One good and one bad task does not error
$ ${TURBO} run build doesnotexist
ERROR run failed: error preparing engine: Could not find the following tasks in project: doesnotexist
Turbo error: error preparing engine: Could not find the following tasks in project: doesnotexist
[1]
14 changes: 13 additions & 1 deletion cli/internal/core/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ func (e *Engine) Prepare(options *EngineBuildingOptions) error {

traversalQueue := []string{}

// get a set of taskNames passed in. we'll remove the ones that have a definition
missing := util.SetFromStrings(taskNames)

// Get a list of entry points into our TaskGraph.
// We do this by taking the input taskNames, and pkgs
// and creating a queue of taskIDs that we can traverse and gather dependencies from.
Expand All @@ -180,14 +183,23 @@ func (e *Engine) Prepare(options *EngineBuildingOptions) error {

return err
}

// delete taskName if it was found
missing.Delete(taskName)
traversalQueue = append(traversalQueue, taskID)
}
}
}

visited := make(util.Set)

// validate that all tasks passed were found
missingList := missing.UnsafeListOfStrings()
sort.Strings(missingList)

if len(missingList) > 0 {
return fmt.Errorf("Could not find the following tasks in project: %s", strings.Join(missingList, ", "))
}

// Things get appended to traversalQueue inside this loop, so we use the len() check instead of range.
for len(traversalQueue) > 0 {
// pop off the first item from the traversalQueue
Expand Down

0 comments on commit 0186f61

Please sign in to comment.