func-common.go common-errors.go
This commit is contained in:
parent
5643a57bcc
commit
6a2d3c53fd
37
common-errors.go
Normal file
37
common-errors.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// common-errors.go
|
||||||
|
package expr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// --- General errors
|
||||||
|
|
||||||
|
func errCantConvert(funcName string, value any, kind string) error {
|
||||||
|
return fmt.Errorf("%s() can't convert %T to %s", funcName, value, kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
func errExpectedGot(funcName string, kind string, value any) error {
|
||||||
|
return fmt.Errorf("%s() expected %s, got %T (%v)", funcName, kind, value, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Parameter errors
|
||||||
|
|
||||||
|
func errOneParam(funcName string) error {
|
||||||
|
return fmt.Errorf("%s() requires exactly one param", funcName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func errMissingRequiredParameter(funcName, paramName string) error {
|
||||||
|
return fmt.Errorf("%s() missing required parameter %q", funcName, paramName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func errInvalidParameterValue(funcName, paramName string, paramValue any) error {
|
||||||
|
return fmt.Errorf("%s() invalid value %T (%v) for parameter %q", funcName, paramValue, paramValue, paramName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func errWrongParamType(funcName, paramName, paramType string, paramValue any) error {
|
||||||
|
return fmt.Errorf("%s() the %q parameter must be a %s, got a %T (%v)", funcName, paramName, paramType, paramValue, paramValue)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user