2023-04-15 22:22:25 +02:00
|
|
|
package errors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-09-12 23:42:54 +02:00
|
|
|
"net/http"
|
2023-11-17 22:51:10 +02:00
|
|
|
"time"
|
2023-04-15 22:22:25 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// TaskfileNotFoundError is returned when no appropriate Taskfile is found when
|
|
|
|
// searching the filesystem.
|
|
|
|
type TaskfileNotFoundError struct {
|
2023-09-02 22:24:01 +02:00
|
|
|
URI string
|
2023-04-15 22:22:25 +02:00
|
|
|
Walk bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err TaskfileNotFoundError) Error() string {
|
|
|
|
var walkText string
|
|
|
|
if err.Walk {
|
|
|
|
walkText = " (or any of the parent directories)"
|
|
|
|
}
|
2023-09-12 23:42:54 +02:00
|
|
|
return fmt.Sprintf(`task: No Taskfile found at %q%s`, err.URI, walkText)
|
2023-04-15 22:22:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2023-09-02 22:24:01 +02:00
|
|
|
URI string
|
|
|
|
Err error
|
2023-04-15 22:22:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (err TaskfileInvalidError) Error() string {
|
2023-09-02 22:24:01 +02:00
|
|
|
return fmt.Sprintf("task: Failed to parse %s:\n%v", err.URI, err.Err)
|
2023-04-15 22:22:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (err TaskfileInvalidError) Code() int {
|
|
|
|
return CodeTaskfileInvalid
|
|
|
|
}
|
2023-09-12 23:42:54 +02:00
|
|
|
|
|
|
|
// 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`, 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`,
|
|
|
|
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`,
|
|
|
|
err.URI,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *TaskfileNotSecureError) Code() int {
|
|
|
|
return CodeTaskfileNotSecure
|
|
|
|
}
|
|
|
|
|
|
|
|
// TaskfileCacheNotFound is returned when the user attempts to use an offline
|
|
|
|
// (cached) Taskfile but the files does not exist in the cache.
|
|
|
|
type TaskfileCacheNotFound struct {
|
|
|
|
URI string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *TaskfileCacheNotFound) 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`,
|
|
|
|
err.URI,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *TaskfileCacheNotFound) Code() int {
|
|
|
|
return CodeTaskfileCacheNotFound
|
|
|
|
}
|
2023-09-19 20:21:40 +02:00
|
|
|
|
|
|
|
// TaskfileVersionNotDefined is returned when the user attempts to run a
|
|
|
|
// Taskfile that does not contain a Taskfile schema version key.
|
|
|
|
type TaskfileVersionNotDefined struct {
|
|
|
|
URI string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *TaskfileVersionNotDefined) Error() string {
|
|
|
|
return fmt.Sprintf(
|
|
|
|
`task: Taskfile %q does not contain a schema version key`,
|
|
|
|
err.URI,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *TaskfileVersionNotDefined) Code() int {
|
|
|
|
return CodeTaskfileVersionNotDefined
|
|
|
|
}
|
2023-11-17 22:51:10 +02:00
|
|
|
|
|
|
|
// TaskfileNetworkTimeout is returned when the user attempts to use a remote
|
|
|
|
// Taskfile but a network connection could not be established within the timeout.
|
|
|
|
type TaskfileNetworkTimeout struct {
|
|
|
|
URI string
|
|
|
|
Timeout time.Duration
|
|
|
|
CheckedCache bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *TaskfileNetworkTimeout) Error() string {
|
|
|
|
var cacheText string
|
|
|
|
if err.CheckedCache {
|
|
|
|
cacheText = " and no offline copy was found in the cache"
|
|
|
|
}
|
|
|
|
return fmt.Sprintf(
|
|
|
|
`task: Network connection timed out after %s while attempting to download Taskfile %q%s`,
|
|
|
|
err.Timeout, err.URI, cacheText,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *TaskfileNetworkTimeout) Code() int {
|
|
|
|
return CodeTaskfileNetworkTimeout
|
|
|
|
}
|