2017-03-03 01:48:00 +02:00
|
|
|
package task
|
|
|
|
|
|
|
|
import (
|
2017-06-04 21:02:04 +02:00
|
|
|
"errors"
|
2017-03-03 01:48:00 +02:00
|
|
|
"fmt"
|
2022-10-02 00:39:44 +02:00
|
|
|
"strings"
|
2022-06-12 01:01:48 +02:00
|
|
|
|
2022-06-02 14:22:00 +02:00
|
|
|
"mvdan.cc/sh/v3/interp"
|
2017-03-03 01:48:00 +02:00
|
|
|
)
|
|
|
|
|
2023-03-31 21:13:29 +02:00
|
|
|
// ErrTaskfileAlreadyExists is returned on creating a Taskfile if one already exists
|
|
|
|
var ErrTaskfileAlreadyExists = errors.New("task: A Taskfile already exists")
|
2017-06-04 21:02:04 +02:00
|
|
|
|
2017-03-03 01:48:00 +02:00
|
|
|
type taskNotFoundError struct {
|
2022-10-02 17:49:38 +02:00
|
|
|
taskName string
|
|
|
|
didYouMean string
|
2017-03-03 01:48:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (err *taskNotFoundError) Error() string {
|
2022-10-02 17:49:38 +02:00
|
|
|
if err.didYouMean != "" {
|
|
|
|
return fmt.Sprintf(
|
|
|
|
`task: Task %q does not exist. Did you mean %q?`,
|
|
|
|
err.taskName,
|
|
|
|
err.didYouMean,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf(`task: Task %q does not exist`, err.taskName)
|
2017-03-03 01:48:00 +02:00
|
|
|
}
|
|
|
|
|
2022-10-02 00:39:44 +02:00
|
|
|
type multipleTasksWithAliasError struct {
|
|
|
|
aliasName string
|
|
|
|
taskNames []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *multipleTasksWithAliasError) Error() string {
|
|
|
|
return fmt.Sprintf(`task: Multiple tasks (%s) with alias %q found`, strings.Join(err.taskNames, ", "), err.aliasName)
|
|
|
|
}
|
|
|
|
|
2022-07-22 04:15:35 +02:00
|
|
|
type taskInternalError struct {
|
|
|
|
taskName string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *taskInternalError) Error() string {
|
|
|
|
return fmt.Sprintf(`task: Task "%s" is internal`, err.taskName)
|
|
|
|
}
|
|
|
|
|
2022-06-02 14:22:00 +02:00
|
|
|
type TaskRunError struct {
|
2017-03-03 01:48:00 +02:00
|
|
|
taskName string
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
2022-06-02 14:22:00 +02:00
|
|
|
func (err *TaskRunError) Error() string {
|
2022-08-17 19:37:58 +02:00
|
|
|
return fmt.Sprintf(`task: Failed to run task %q: %v`, err.taskName, err.err)
|
2017-03-03 01:48:00 +02:00
|
|
|
}
|
|
|
|
|
2022-06-02 14:22:00 +02:00
|
|
|
func (err *TaskRunError) ExitCode() int {
|
|
|
|
if c, ok := interp.IsExitStatus(err.err); ok {
|
|
|
|
return int(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:33:55 +02:00
|
|
|
// MaximumTaskCallExceededError is returned when a task is called too
|
|
|
|
// many times. In this case you probably have a cyclic dependendy or
|
|
|
|
// infinite loop
|
|
|
|
type MaximumTaskCallExceededError struct {
|
|
|
|
task string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *MaximumTaskCallExceededError) Error() string {
|
|
|
|
return fmt.Sprintf(
|
2022-08-17 19:37:58 +02:00
|
|
|
`task: maximum task call exceeded (%d) for task %q: probably an cyclic dep or infinite loop`,
|
2017-07-08 18:33:55 +02:00
|
|
|
MaximumTaskCall,
|
|
|
|
e.task,
|
|
|
|
)
|
|
|
|
}
|