require less English

This commit is contained in:
Adrien Delorme 2020-11-04 13:13:45 +01:00
parent 2987d25335
commit 10eb32d29e
1 changed files with 17 additions and 20 deletions

View File

@ -371,10 +371,10 @@ type VariableValidation struct {
// the block defining the validation rule, not an error in the caller. // the block defining the validation rule, not an error in the caller.
Condition hcl.Expression Condition hcl.Expression
// ErrorMessage is one or more full sentences, which would need to be in // ErrorMessage is one or more full sentences, which _should_ be in English
// English for consistency with the rest of the error message output but // for consistency with the rest of the error message output but can in
// can in practice be in any language as long as it ends with a period. // practice be in any language as long as it ends with a period. The
// The message should describe what is required for the condition to return // message should describe what is required for the condition to return
// true in a way that would make sense to a caller of the module. // true in a way that would make sense to a caller of the module.
ErrorMessage string ErrorMessage string
@ -442,20 +442,19 @@ func decodeVariableValidationBlock(varName string, block *hcl.Block) (*VariableV
}) })
case !looksLikeSentences(vv.ErrorMessage): case !looksLikeSentences(vv.ErrorMessage):
// Because we're going to include this string verbatim as part // Because we're going to include this string verbatim as part
// of a bigger error message written in our usual style in // of a bigger error message written in our usual style, we'll
// English, we'll require the given error message to conform // require the given error message to conform to that. We might
// to that. We might relax this in future if e.g. we start // relax this in future if e.g. we start presenting these error
// presenting these error messages in a different way, or if // messages in a different way, or if Packer starts supporting
// Packer starts supporting producing error messages in // producing error messages in other human languages, etc. For
// other human languages, etc. // pragmatism we also allow sentences ending with exclamation
// For pragmatism we also allow sentences ending with // points, but we don't mention it explicitly here because
// exclamation points, but we don't mention it explicitly here // that's not really consistent with the Packer UI writing
// because that's not really consistent with the Packer UI // style.
// writing style.
diags = diags.Append(&hcl.Diagnostic{ diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError, Severity: hcl.DiagError,
Summary: errSummary, Summary: errSummary,
Detail: "Validation error message must be at least one full English sentence starting with an uppercase letter and ending with a period or question mark.", Detail: "Validation error message must be at least one full sentence starting with an uppercase letter ( if the alphabet permits it ) and ending with a period or question mark.",
Subject: attr.Expr.Range().Ptr(), Subject: attr.Expr.Range().Ptr(),
}) })
} }
@ -481,11 +480,9 @@ func looksLikeSentences(s string) bool {
first := runes[0] first := runes[0]
last := runes[len(runes)-1] last := runes[len(runes)-1]
// If the first rune is a letter then it must be an uppercase letter. // If the first rune is a letter then it must be an uppercase letter. To
// (This will only see the first rune in a multi-rune combining sequence, // sorts of nudge people into writting sentences. For alphabets that don't
// but the first rune is generally the letter if any are, and if not then // have the notion of 'upper', this does nothing.
// we'll just ignore it because we're primarily expecting English messages
// right now anyway, for consistency with all of Packers's other output.)
if unicode.IsLetter(first) && !unicode.IsUpper(first) { if unicode.IsLetter(first) && !unicode.IsUpper(first) {
return false return false
} }