62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
// All rights reserved.
|
|
|
|
// common-errors.go
|
|
package expr
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func ErrTooFewParams(funcName string, minArgs, maxArgs, argCount int) (err error) {
|
|
if maxArgs < 0 {
|
|
err = fmt.Errorf("%s(): too few params -- expected %d or more, got %d", funcName, minArgs, argCount)
|
|
} else {
|
|
err = fmt.Errorf("%s(): too few params -- expected %d, got %d", funcName, minArgs, argCount)
|
|
}
|
|
return
|
|
}
|
|
|
|
func ErrTooMuchParams(funcName string, maxArgs, argCount int) (err error) {
|
|
err = fmt.Errorf("%s(): too much params -- expected %d, got %d", funcName, maxArgs, argCount)
|
|
return
|
|
}
|
|
|
|
// --- General errors
|
|
|
|
func ErrCantConvert(funcName string, value any, kind string) error {
|
|
return fmt.Errorf("%s(): can't convert %s to %s", funcName, TypeName(value), kind)
|
|
}
|
|
|
|
func ErrExpectedGot(funcName string, kind string, value any) error {
|
|
return fmt.Errorf("%s(): expected %s, got %s (%v)", funcName, kind, TypeName(value), value)
|
|
}
|
|
|
|
func ErrFuncDivisionByZero(funcName string) error {
|
|
return fmt.Errorf("%s(): division by zero", funcName)
|
|
}
|
|
|
|
// func ErrDivisionByZero() error {
|
|
// return fmt.Errorf("division by zero")
|
|
// }
|
|
|
|
// --- Parameter errors
|
|
|
|
// 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 %s (%v) for parameter %q", funcName, TypeName(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 %s (%v)", funcName, paramName, paramType, TypeName(paramValue), paramValue)
|
|
}
|
|
|
|
// --- Operator errors
|
|
|
|
func ErrLeftOperandMustBeVariable(leftTerm, opTerm *term) error {
|
|
return leftTerm.Errorf("left operand of %q must be a variable", opTerm.source())
|
|
}
|