forked from go-task/task
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors_task.go
147 lines (119 loc) · 3.56 KB
/
errors_task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package errors
import (
"fmt"
"strings"
"mvdan.cc/sh/v3/interp"
)
// TaskNotFoundError is returned when the specified task is not found in the
// Taskfile.
type TaskNotFoundError struct {
TaskName string
DidYouMean string
}
func (err *TaskNotFoundError) Error() string {
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)
}
func (err *TaskNotFoundError) Code() int {
return CodeTaskNotFound
}
// TaskRunError is returned when a command in a task returns a non-zero exit
// code.
type TaskRunError struct {
TaskName string
Err error
}
func (err *TaskRunError) Error() string {
return fmt.Sprintf(`task: Failed to run task %q: %v`, err.TaskName, err.Err)
}
func (err *TaskRunError) Code() int {
return CodeTaskRunError
}
func (err *TaskRunError) TaskExitCode() int {
if c, ok := interp.IsExitStatus(err.Err); ok {
return int(c)
}
return err.Code()
}
// TaskInternalError when the user attempts to invoke a task that is internal.
type TaskInternalError struct {
TaskName string
}
func (err *TaskInternalError) Error() string {
return fmt.Sprintf(`task: Task "%s" is internal`, err.TaskName)
}
func (err *TaskInternalError) Code() int {
return CodeTaskInternal
}
// TaskNameConflictError is returned when multiple tasks with the same name or
// alias are found.
type TaskNameConflictError struct {
AliasName string
TaskNames []string
}
func (err *TaskNameConflictError) Error() string {
return fmt.Sprintf(`task: Multiple tasks (%s) with alias %q found`, strings.Join(err.TaskNames, ", "), err.AliasName)
}
func (err *TaskNameConflictError) Code() int {
return CodeTaskNameConflict
}
// TaskCalledTooManyTimesError is returned when the maximum task call limit is
// exceeded. This is to prevent infinite loops and cyclic dependencies.
type TaskCalledTooManyTimesError struct {
TaskName string
MaximumTaskCall int
}
func (err *TaskCalledTooManyTimesError) Error() string {
return fmt.Sprintf(
`task: Maximum task call exceeded (%d) for task %q: probably an cyclic dep or infinite loop`,
err.MaximumTaskCall,
err.TaskName,
)
}
func (err *TaskCalledTooManyTimesError) Code() int {
return CodeTaskCalledTooManyTimes
}
// TaskCancelledByUserError is returned when the user does not accept an optional prompt to continue.
type TaskCancelledByUserError struct {
TaskName string
}
func (err *TaskCancelledByUserError) Error() string {
return fmt.Sprintf(`task: Task %q cancelled by user`, err.TaskName)
}
func (err *TaskCancelledByUserError) Code() int {
return CodeTaskCancelled
}
// TaskCancelledNoTerminalError is returned when trying to run a task with a prompt in a non-terminal environment.
type TaskCancelledNoTerminalError struct {
TaskName string
}
func (err *TaskCancelledNoTerminalError) Error() string {
return fmt.Sprintf(
`task: Task %q cancelled because it has a prompt and the environment is not a terminal. Use --yes (-y) to run anyway.`,
err.TaskName,
)
}
func (err *TaskCancelledNoTerminalError) Code() int {
return CodeTaskCancelled
}
// TaskMissingRequiredVars is returned when a task is missing required variables.
type TaskMissingRequiredVars struct {
TaskName string
MissingVars []string
}
func (err *TaskMissingRequiredVars) Error() string {
return fmt.Sprintf(
`task: Task %q cancelled because it is missing required variables: %s`,
err.TaskName,
strings.Join(err.MissingVars, ", "),
)
}
func (err *TaskMissingRequiredVars) Code() int {
return CodeTaskMissingRequiredVars
}