Skip to content

Commit

Permalink
streamline validation error output
Browse files Browse the repository at this point in the history
  • Loading branch information
jippi committed Feb 6, 2024
1 parent 4a5b73a commit 53e8730
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/validation/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,24 @@ func Explain(env *ast.Document, keyErr ValidationError) {
light.Println("(file) The file [" + bold.Sprintf(keyErr.Assignment.Interpolated) + "] does not exist.")

case "oneof":
light.Println("(oneof) The value [" + bold.Sprintf(keyErr.Assignment.Interpolated) + "] must be one of [" + rule.Param() + "]")
light.Println("(oneof) The value [" + bold.Sprintf(keyErr.Assignment.Interpolated) + "] is not one of [" + rule.Param() + "]")

case "number":
light.Println("(number) The value [" + bold.Sprintf(keyErr.Assignment.Interpolated) + "] is not a valid number")

case "email":
light.Println("(email) Expected a valid e-mail, but got [" + bold.Sprintf(keyErr.Assignment.Interpolated) + "].")
light.Println("(email) The value [" + bold.Sprintf(keyErr.Assignment.Interpolated) + "] is not a valid e-mail")
AskToSetValue(env, keyErr.Assignment)

case "required":
light.Println("(required) This key must not have an empty value.")
light.Println("(required) This value must not be empty/blank.")

case "fqdn":
light.Println("(fqdn) This key must have a valid hostname.")
light.Println("(fqdn) The value [" + bold.Sprintf(keyErr.Assignment.Interpolated) + "] is not a valid Fully Qualified Domain Name (FQDN).")
AskToSetValue(env, keyErr.Assignment)

default:
light.Printfln("(%s) failed validation", rule.ActualTag())
light.Printfln("(%s) The value ["+bold.Sprintf(keyErr.Assignment.Interpolated)+"] failed validation", rule.ActualTag())
}
}

Expand Down

0 comments on commit 53e8730

Please sign in to comment.