From 79b7cc542a4047f64d4436b28e13acf5ee4b604c Mon Sep 17 00:00:00 2001 From: Fabian Kramm Date: Fri, 26 Aug 2022 11:20:04 +0200 Subject: [PATCH 1/2] fix: improve unmarshal error --- pkg/util/yamlutil/yaml.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/util/yamlutil/yaml.go b/pkg/util/yamlutil/yaml.go index 6ac024dfdc..f4540cfbef 100644 --- a/pkg/util/yamlutil/yaml.go +++ b/pkg/util/yamlutil/yaml.go @@ -43,6 +43,17 @@ func Unmarshal(data []byte, out interface{}) error { func prettifyError(data []byte, err error) error { // check if type error if typeError, ok := err.(*yaml.TypeError); ok { + // print the config with lines + lines := strings.Split(string(data), "\n") + extraLines := []string{"Parsed Config:"} + for i, v := range lines { + if v == "" { + continue + } + extraLines = append(extraLines, fmt.Sprintf(" %d: %s", i+1, v)) + } + extraLines = append(extraLines, "Errors:") + for i := range typeError.Errors { typeError.Errors[i] = strings.ReplaceAll(typeError.Errors[i], "!!seq", "an array") typeError.Errors[i] = strings.ReplaceAll(typeError.Errors[i], "!!str", "string") @@ -58,11 +69,14 @@ func prettifyError(data []byte, err error) error { line = line - 1 lines := strings.Split(string(data), "\n") if line < len(lines) { - typeError.Errors[i] += fmt.Sprintf(" (line %d: %s)", line+1, strings.TrimSpace(lines[line])) + typeError.Errors[i] = " " + typeError.Errors[i] + fmt.Sprintf(" (line %d: %s)", line+1, strings.TrimSpace(lines[line])) } } } } + + extraLines = append(extraLines, typeError.Errors...) + typeError.Errors = extraLines } return err From 0b9bc10b9eec4866c146c2744949ac89d25424c2 Mon Sep 17 00:00:00 2001 From: Fabian Kramm Date: Fri, 26 Aug 2022 11:29:32 +0200 Subject: [PATCH 2/2] fix: print error if reserved function --- pkg/devspace/config/versions/validate.go | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/devspace/config/versions/validate.go b/pkg/devspace/config/versions/validate.go index 87472e7d17..00f3b68350 100644 --- a/pkg/devspace/config/versions/validate.go +++ b/pkg/devspace/config/versions/validate.go @@ -91,6 +91,34 @@ func Validate(config *latest.Config) error { return err } + err = validateFunctions(config.Functions) + if err != nil { + return err + } + + return nil +} + +func isReservedFunctionName(name string) bool { + switch name { + case "true", ":", "false", "exit", "set", "shift", "unset", + "echo", "printf", "break", "continue", "pwd", "cd", + "wait", "builtin", "trap", "type", "source", ".", "command", + "dirs", "pushd", "popd", "umask", "alias", "unalias", + "fg", "bg", "getopts", "eval", "test", "devspace", "[", "exec", + "return", "read", "shopt": + return true + } + return false +} + +func validateFunctions(functions map[string]string) error { + for name := range functions { + if isReservedFunctionName(name) { + return fmt.Errorf("you cannot use '%s' as a function name as its an internally used special function. Please choose another name", name) + } + } + return nil }