1
0
mirror of https://github.com/go-task/task.git synced 2025-11-23 22:24:45 +02:00

feat: error handling for undefined schema version (#1342)

* feat: error handling for undefined schema version

* docs: error codes

* chore: changelog
This commit is contained in:
Pete Davison
2023-09-19 13:21:40 -05:00
committed by GitHub
parent b1ff13d3e8
commit 078e213890
5 changed files with 38 additions and 3 deletions

View File

@@ -1,5 +1,12 @@
# Changelog
## Unreleased
- Fixed a nil pointer error when running a Taskfile with no contents (#1341,
#1342 by @pd93).
- Added a new [exit code](https://taskfile.dev/api/#exit-codes) (107) for when a
Taskfile does not contain a schema version (#1342 by @pd93).
## v3.30.1 - 2023-09-14
- Fixed a regression where some special variables weren't being set correctly

View File

@@ -70,6 +70,11 @@ A full list of the exit codes and their descriptions can be found below:
| 100 | No Taskfile was found |
| 101 | A Taskfile already exists when trying to initialize one |
| 102 | The Taskfile is invalid or cannot be parsed |
| 103 | A remote Taskfile could not be downlaoded |
| 104 | A remote Taskfile was not trusted by the user |
| 105 | A remote Taskfile was could not be fetched securely |
| 106 | No cache was found for a remote Taskfile in offline mode |
| 107 | No schema version was defined in the Taskfile |
| 200 | The specified task could not be found |
| 201 | An error occurred while executing a command inside of a task |
| 202 | The user tried to invoke a task that is internal |

View File

@@ -17,6 +17,7 @@ const (
CodeTaskfileNotTrusted
CodeTaskfileNotSecure
CodeTaskfileCacheNotFound
CodeTaskfileVersionNotDefined
)
// Task related exit codes

View File

@@ -120,3 +120,20 @@ func (err *TaskfileCacheNotFound) Error() string {
func (err *TaskfileCacheNotFound) Code() int {
return CodeTaskfileCacheNotFound
}
// 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
}

View File

@@ -147,6 +147,11 @@ func Taskfile(
return nil, err
}
// Check that the Taskfile is set and has a schema version
if t == nil || t.Version == nil {
return nil, &errors.TaskfileVersionNotDefined{URI: node.Location()}
}
// Annotate any included Taskfile reference with a base directory for resolving relative paths
if node, isFileNode := node.(*FileNode); isFileNode {
_ = t.Includes.Range(func(key string, includedFile taskfile.IncludedTaskfile) error {