1
0
mirror of https://github.com/go-task/task.git synced 2025-11-25 22:32:55 +02:00

feat: decoding improvements (#2068)

* refactor: moved/simplified snippets into its own file with tests

* refactor: move snippet to taskfile package

* feat: support snippets with line/col = 0

* feat: functional options for snippets

* feat: added option to hide snippet indicators

* feat: store raw lines for length calculations

* feat: add debug function for TaskfileDecodeError

* fix: decode errors from commands

* fix: schema for defer cmd calls

* fix: linting issues

* refactor: split var and vars into different files like other structures
This commit is contained in:
Pete Davison
2025-02-22 15:44:22 +00:00
committed by GitHub
parent fb27318601
commit cdb6a3f70a
10 changed files with 753 additions and 282 deletions

View File

@@ -193,9 +193,14 @@ func (r *Reader) readNode(node Node) (*ast.Taskfile, error) {
var tf ast.Taskfile
if err := yaml.Unmarshal(b, &tf); err != nil {
// Decode the taskfile and add the file info the any errors
taskfileInvalidErr := &errors.TaskfileDecodeError{}
if errors.As(err, &taskfileInvalidErr) {
return nil, taskfileInvalidErr.WithFileInfo(node.Location(), b, 2)
taskfileDecodeErr := &errors.TaskfileDecodeError{}
if errors.As(err, &taskfileDecodeErr) {
snippet := NewSnippet(b,
SnippetWithLine(taskfileDecodeErr.Line),
SnippetWithColumn(taskfileDecodeErr.Column),
SnippetWithPadding(2),
)
return nil, taskfileDecodeErr.WithFileInfo(node.Location(), snippet.String())
}
return nil, &errors.TaskfileInvalidError{URI: filepathext.TryAbsToRel(node.Location()), Err: err}
}