-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: show all persistent task validation errors #5807
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -454,12 +454,12 @@ func (e *Engine) AddDep(fromTaskID string, toTaskID string) error { | |
// ValidatePersistentDependencies checks if any task dependsOn persistent tasks and throws | ||
// an error if that task is actually implemented | ||
func (e *Engine) ValidatePersistentDependencies(graph *graph.CompleteGraph, concurrency int) error { | ||
var validationError error | ||
var validationErrors []string | ||
persistentCount := 0 | ||
|
||
// Adding in a lock because otherwise walking the graph can introduce a data race | ||
// (reproducible with `go test -race`) | ||
var sema = util.NewSemaphore(1) | ||
var mu sync.Mutex | ||
|
||
errs := e.TaskGraph.Walk(func(v dag.Vertex) error { | ||
vertexName := dag.VertexName(v) // vertexName is a taskID | ||
|
@@ -469,12 +469,6 @@ func (e *Engine) ValidatePersistentDependencies(graph *graph.CompleteGraph, conc | |
return nil | ||
} | ||
|
||
// Aquire a lock, because otherwise walking this group can cause a race condition | ||
// writing to the same validationError var defined outside the Walk(). This shows | ||
// up when running tests with the `-race` flag. | ||
sema.Acquire() | ||
defer sema.Release() | ||
|
||
currentTaskDefinition, currentTaskExists := e.completeGraph.TaskDefinitions[vertexName] | ||
if currentTaskExists && currentTaskDefinition.Persistent { | ||
persistentCount++ | ||
|
@@ -511,11 +505,16 @@ func (e *Engine) ValidatePersistentDependencies(graph *graph.CompleteGraph, conc | |
|
||
// If both conditions are true set a value and break out of checking the dependencies | ||
if depTaskDefinition.Persistent && hasScript { | ||
validationError = fmt.Errorf( | ||
// Aquire a lock, because otherwise walking this group can cause a race condition | ||
// writing to the same validationErrors var defined outside the Walk(). This shows | ||
// up when running tests with the `-race` flag. | ||
mu.Lock() | ||
defer mu.Unlock() | ||
Comment on lines
+511
to
+512
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the locking/unlocking to only where we write to some shared state |
||
validationErrors = append(validationErrors, fmt.Sprintf( | ||
"\"%s\" is a persistent task, \"%s\" cannot depend on it", | ||
util.GetTaskId(packageName, taskName), | ||
util.GetTaskId(currentPackageName, currentTaskName), | ||
) | ||
)) | ||
|
||
break | ||
} | ||
|
@@ -528,8 +527,9 @@ func (e *Engine) ValidatePersistentDependencies(graph *graph.CompleteGraph, conc | |
return fmt.Errorf("Validation failed: %v", err) | ||
} | ||
|
||
if validationError != nil { | ||
return validationError | ||
if len(validationErrors) > 0 { | ||
sort.Strings(validationErrors) | ||
return fmt.Errorf("%s", strings.Join(validationErrors, "\n")) | ||
} else if persistentCount >= concurrency { | ||
return fmt.Errorf("You have %v persistent tasks but `turbo` is configured for concurrency of %v. Set --concurrency to at least %v", persistentCount, concurrency, persistentCount+1) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,7 +184,11 @@ impl Run { | |
.map_err(|errors| { | ||
anyhow!( | ||
"error preparing engine: Invalid persistent task configuration:\n{}", | ||
errors.into_iter().join("\n") | ||
errors | ||
.into_iter() | ||
.map(|e| e.to_string()) | ||
.sorted() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now the Rust version is deterministic |
||
.join("\n") | ||
) | ||
})?; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't strictly necessary, but we really just want a mutex guarding the validation errors and not a semaphore.