mirror of
https://github.com/go-task/task.git
synced 2025-07-13 01:30:33 +02:00
feat: better taskfile cycle error handling
This commit is contained in:
@ -20,6 +20,7 @@ const (
|
|||||||
CodeTaskfileVersionCheckError
|
CodeTaskfileVersionCheckError
|
||||||
CodeTaskfileNetworkTimeout
|
CodeTaskfileNetworkTimeout
|
||||||
CodeTaskfileDuplicateInclude
|
CodeTaskfileDuplicateInclude
|
||||||
|
CodeTaskfileCycle
|
||||||
)
|
)
|
||||||
|
|
||||||
// Task related exit codes
|
// Task related exit codes
|
||||||
|
@ -191,3 +191,21 @@ func (err *TaskfileDuplicateIncludeError) Error() string {
|
|||||||
func (err *TaskfileDuplicateIncludeError) Code() int {
|
func (err *TaskfileDuplicateIncludeError) Code() int {
|
||||||
return CodeTaskfileDuplicateInclude
|
return CodeTaskfileDuplicateInclude
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TaskfileCycleError is returned when we detect that a Taskfile includes a
|
||||||
|
// set of Taskfiles that include each other in a cycle.
|
||||||
|
type TaskfileCycleError struct {
|
||||||
|
Source string
|
||||||
|
Destination string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err TaskfileCycleError) Error() string {
|
||||||
|
return fmt.Sprintf("task: include cycle detected between %s <--> %s",
|
||||||
|
err.Source,
|
||||||
|
err.Destination,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err TaskfileCycleError) Code() int {
|
||||||
|
return CodeTaskfileCycle
|
||||||
|
}
|
||||||
|
@ -153,6 +153,12 @@ func (r *Reader) include(node Node) error {
|
|||||||
Namespaces: []string{namespace, edge.Properties.Data.(*ast.Include).Namespace},
|
Namespaces: []string{namespace, edge.Properties.Data.(*ast.Include).Namespace},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if errors.Is(err, graph.ErrEdgeCreatesCycle) {
|
||||||
|
return errors.TaskfileCycleError{
|
||||||
|
Source: node.Location(),
|
||||||
|
Destination: includeNode.Location(),
|
||||||
|
}
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user