-
-
Notifications
You must be signed in to change notification settings - Fork 817
Expand file tree
/
Copy patherrors_taskfile.go
More file actions
215 lines (180 loc) · 5.73 KB
/
errors_taskfile.go
File metadata and controls
215 lines (180 loc) · 5.73 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package errors
import (
"fmt"
"net/http"
"path/filepath"
"time"
"github.com/Masterminds/semver/v3"
)
// TaskfileNotFoundError is returned when no appropriate Taskfile is found when
// searching the filesystem.
type TaskfileNotFoundError struct {
URI string
Walk bool
AskInit bool
}
func (err TaskfileNotFoundError) Error() string {
var walkText string
if err.Walk {
walkText = " (or any of the parent directories)."
}
if err.AskInit {
walkText += " Run `task --init` to create a new Taskfile."
}
return fmt.Sprintf(`task: No Taskfile found at %q%s`, filepath.ToSlash(err.URI), walkText)
}
func (err TaskfileNotFoundError) Code() int {
return CodeTaskfileNotFound
}
// TaskfileAlreadyExistsError is returned on creating a Taskfile if one already
// exists.
type TaskfileAlreadyExistsError struct{}
func (err TaskfileAlreadyExistsError) Error() string {
return "task: A Taskfile already exists"
}
func (err TaskfileAlreadyExistsError) Code() int {
return CodeTaskfileAlreadyExists
}
// TaskfileInvalidError is returned when the Taskfile contains syntax errors or
// cannot be parsed for some reason.
type TaskfileInvalidError struct {
URI string
Err error
}
func (err TaskfileInvalidError) Error() string {
return fmt.Sprintf("task: Failed to parse %s:\n%v", filepath.ToSlash(err.URI), err.Err)
}
func (err TaskfileInvalidError) Code() int {
return CodeTaskfileInvalid
}
// TaskfileFetchFailedError is returned when no appropriate Taskfile is found when
// searching the filesystem.
type TaskfileFetchFailedError struct {
URI string
HTTPStatusCode int
}
func (err TaskfileFetchFailedError) Error() string {
var statusText string
if err.HTTPStatusCode != 0 {
statusText = fmt.Sprintf(" with status code %d (%s)", err.HTTPStatusCode, http.StatusText(err.HTTPStatusCode))
}
return fmt.Sprintf(`task: Download of %q failed%s`, filepath.ToSlash(err.URI), statusText)
}
func (err TaskfileFetchFailedError) Code() int {
return CodeTaskfileFetchFailed
}
// TaskfileNotTrustedError is returned when the user does not accept the trust
// prompt when downloading a remote Taskfile.
type TaskfileNotTrustedError struct {
URI string
}
func (err *TaskfileNotTrustedError) Error() string {
return fmt.Sprintf(
`task: Taskfile %q not trusted by user`,
filepath.ToSlash(err.URI),
)
}
func (err *TaskfileNotTrustedError) Code() int {
return CodeTaskfileNotTrusted
}
// TaskfileNotSecureError is returned when the user attempts to download a
// remote Taskfile over an insecure connection.
type TaskfileNotSecureError struct {
URI string
}
func (err *TaskfileNotSecureError) Error() string {
return fmt.Sprintf(
`task: Taskfile %q cannot be downloaded over an insecure connection. You can override this by using the --insecure flag`,
filepath.ToSlash(err.URI),
)
}
func (err *TaskfileNotSecureError) Code() int {
return CodeTaskfileNotSecure
}
// TaskfileCacheNotFoundError is returned when the user attempts to use an offline
// (cached) Taskfile but the files does not exist in the cache.
type TaskfileCacheNotFoundError struct {
URI string
}
func (err *TaskfileCacheNotFoundError) Error() string {
return fmt.Sprintf(
`task: Taskfile %q was not found in the cache. Remove the --offline flag to use a remote copy or download it using the --download flag`,
filepath.ToSlash(err.URI),
)
}
func (err *TaskfileCacheNotFoundError) Code() int {
return CodeTaskfileCacheNotFound
}
// TaskfileVersionCheckError is returned when the user attempts to run a
// Taskfile that does not contain a Taskfile schema version key or if they try
// to use a feature that is not supported by the schema version.
type TaskfileVersionCheckError struct {
URI string
SchemaVersion *semver.Version
Message string
}
func (err *TaskfileVersionCheckError) Error() string {
if err.SchemaVersion == nil {
return fmt.Sprintf(
`task: Missing schema version in Taskfile %q`,
filepath.ToSlash(err.URI),
)
}
return fmt.Sprintf(
"task: Invalid schema version in Taskfile %q:\nSchema version (%s) %s",
filepath.ToSlash(err.URI),
err.SchemaVersion.String(),
err.Message,
)
}
func (err *TaskfileVersionCheckError) Code() int {
return CodeTaskfileVersionCheckError
}
// TaskfileNetworkTimeoutError is returned when the user attempts to use a remote
// Taskfile but a network connection could not be established within the timeout.
type TaskfileNetworkTimeoutError struct {
URI string
Timeout time.Duration
}
func (err *TaskfileNetworkTimeoutError) Error() string {
return fmt.Sprintf(
`task: Network connection timed out after %s while attempting to download Taskfile %q`,
err.Timeout, filepath.ToSlash(err.URI),
)
}
func (err *TaskfileNetworkTimeoutError) Code() int {
return CodeTaskfileNetworkTimeout
}
// 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",
filepath.ToSlash(err.Source),
filepath.ToSlash(err.Destination),
)
}
func (err TaskfileCycleError) Code() int {
return CodeTaskfileCycle
}
// TaskfileDoesNotMatchChecksum is returned when a Taskfile's checksum does not
// match the one pinned in the parent Taskfile.
type TaskfileDoesNotMatchChecksum struct {
URI string
ExpectedChecksum string
ActualChecksum string
}
func (err *TaskfileDoesNotMatchChecksum) Error() string {
return fmt.Sprintf(
"task: The checksum of the Taskfile at %q does not match!\ngot: %q\nwant: %q",
filepath.ToSlash(err.URI),
err.ActualChecksum,
err.ExpectedChecksum,
)
}
func (err *TaskfileDoesNotMatchChecksum) Code() int {
return CodeTaskfileDoesNotMatchChecksum
}