-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔊 Annotate yaml when an error occurs
- Loading branch information
Showing
4 changed files
with
51 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package node | ||
|
||
import ( | ||
"github.com/goccy/go-yaml" | ||
"github.com/goccy/go-yaml/ast" | ||
) | ||
|
||
func NewPrintableError(err error, node ast.Node) PrintableError { | ||
return PrintableError{ | ||
err: err, | ||
node: node, | ||
} | ||
} | ||
|
||
type PrintableError struct { | ||
err error | ||
node ast.Node | ||
} | ||
|
||
func (p PrintableError) Error() string { | ||
return p.err.Error() | ||
} | ||
|
||
func (p PrintableError) AnnotateSource(src string, colored bool) string { | ||
path, err := yaml.PathString(p.node.GetPath()) | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
source, err := path.AnnotateSource([]byte(src), colored) | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
return string(source) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters