Skip to content

Commit d25eea0

Browse files
committed
refactor: improve yaml errors
1 parent a3808f7 commit d25eea0

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

pkg/util/yamlutil/yaml.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ func Unmarshal(data []byte, out interface{}) error {
3636
func prettifyError(data []byte, err error) error {
3737
// check if type error
3838
if typeError, ok := err.(*yaml.TypeError); ok {
39-
for i, message := range typeError.Errors {
40-
typeError.Errors[i] = strings.Replace(message, "!!seq", "an array", -1)
41-
typeError.Errors[i] = strings.Replace(message, "!!str", "string", -1)
39+
for i := range typeError.Errors {
40+
typeError.Errors[i] = strings.Replace(typeError.Errors[i], "!!seq", "an array", -1)
41+
typeError.Errors[i] = strings.Replace(typeError.Errors[i], "!!str", "string", -1)
42+
typeError.Errors[i] = strings.Replace(typeError.Errors[i], "!!map", "an object", -1)
43+
typeError.Errors[i] = strings.Replace(typeError.Errors[i], "!!int", "number", -1)
44+
typeError.Errors[i] = strings.Replace(typeError.Errors[i], "!!bool", "boolean", -1)
4245

4346
// add line to error
44-
match := lineRegEx.FindSubmatch([]byte(message))
47+
match := lineRegEx.FindSubmatch([]byte(typeError.Errors[i]))
4548
if len(match) > 1 {
4649
line, lineErr := strconv.Atoi(string(match[1]))
4750
if lineErr == nil {

0 commit comments

Comments
 (0)