diff --git a/common-errors.go b/common-errors.go index 23ebe6f..f103c2c 100644 --- a/common-errors.go +++ b/common-errors.go @@ -55,8 +55,25 @@ func ErrInvalidParameterValue(funcName, paramName string, paramValue any) error return fmt.Errorf("%s(): invalid value %s (%v) for parameter %q", funcName, TypeName(paramValue), paramValue, paramName) } +func undefArticle(s string) (article string) { + if len(s) > 0 && strings.Contains("aeiou", s[0:1]) { + article = "an" + } else { + article = "a" + } + return +} + +func prependUndefArticle(s string) (result string) { + return undefArticle(s) + " " + s +} + func ErrWrongParamType(funcName, paramName, paramType string, paramValue any) error { - return fmt.Errorf("%s(): the %q parameter must be a %s, got a %s (%v)", funcName, paramName, paramType, TypeName(paramValue), paramValue) + var artWantType, artGotType string + gotType := TypeName(paramValue) + artGotType = prependUndefArticle(gotType) + artWantType = prependUndefArticle(paramType) + return fmt.Errorf("%s(): the %q parameter must be %s, got %s (%v)", funcName, paramName, artWantType, artGotType, paramValue) } func ErrUnknownParam(funcName, paramName string) error {