config: Generate error copy from valid types map
Renders as: ``` Variable 'invalid_type' type must be one of [string, map, list] - 'not_a_type' is not a valid type ```
This commit is contained in:
parent
cf775ded0e
commit
c1c3127d8e
|
@ -1017,7 +1017,16 @@ func (v *Variable) ValidateTypeAndDefault() error {
|
|||
// If an explicit type is declared, ensure it is valid
|
||||
if v.DeclaredType != "" {
|
||||
if _, ok := typeStringMap[v.DeclaredType]; !ok {
|
||||
return fmt.Errorf("Variable '%s' must be of type string, map, or list - '%s' is not a valid type", v.Name, v.DeclaredType)
|
||||
validTypes := []string{}
|
||||
for k := range typeStringMap {
|
||||
validTypes = append(validTypes, k)
|
||||
}
|
||||
return fmt.Errorf(
|
||||
"Variable '%s' type must be one of [%s] - '%s' is not a valid type",
|
||||
v.Name,
|
||||
strings.Join(validTypes, ", "),
|
||||
v.DeclaredType,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -684,7 +684,7 @@ func TestLoadFile_badVariableTypes(t *testing.T) {
|
|||
}
|
||||
|
||||
errorStr := err.Error()
|
||||
if !strings.Contains(errorStr, "'bad_type' must be of type string") {
|
||||
if !strings.Contains(errorStr, "'bad_type' type must be one of") {
|
||||
t.Fatalf("bad: expected error has wrong text: %s", errorStr)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue