1
0
mirror of https://github.com/go-task/task.git synced 2024-12-12 10:45:49 +02:00
task/errors.go

62 lines
1.3 KiB
Go
Raw Normal View History

2017-03-03 01:48:00 +02:00
package task
import (
"errors"
2017-03-03 01:48:00 +02:00
"fmt"
"mvdan.cc/sh/v3/interp"
2017-03-03 01:48:00 +02:00
)
var (
// ErrTaskfileAlreadyExists is returned on creating a Taskfile if one already exists
ErrTaskfileAlreadyExists = errors.New("task: A Taskfile already exists")
)
2017-03-03 01:48:00 +02:00
type taskNotFoundError struct {
taskName string
}
func (err *taskNotFoundError) Error() string {
2022-08-17 19:37:58 +02:00
return fmt.Sprintf(`task: Task %q not found`, err.taskName)
2017-03-03 01:48:00 +02:00
}
type taskInternalError struct {
taskName string
}
func (err *taskInternalError) Error() string {
return fmt.Sprintf(`task: Task "%s" is internal`, err.taskName)
}
type TaskRunError struct {
2017-03-03 01:48:00 +02:00
taskName string
err error
}
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
}
func (err *TaskRunError) ExitCode() int {
if c, ok := interp.IsExitStatus(err.err); ok {
return int(c)
}
return 1
}
// 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`,
MaximumTaskCall,
e.task,
)
}