New test file for specific code section or data type
This commit is contained in:
+16
-8
@@ -8,32 +8,40 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func errTooFewParams(minArgs, maxArgs, argCount int) (err error) {
|
||||
func errTooFewParams(funcName string, minArgs, maxArgs, argCount int) (err error) {
|
||||
if maxArgs < 0 {
|
||||
err = fmt.Errorf("too few params -- expected %d or more, got %d", minArgs, argCount)
|
||||
err = fmt.Errorf("%s(): too few params -- expected %d or more, got %d", funcName, minArgs, argCount)
|
||||
} else {
|
||||
err = fmt.Errorf("too few params -- expected %d, got %d", minArgs, argCount)
|
||||
err = fmt.Errorf("%s(): too few params -- expected %d, got %d", funcName, minArgs, argCount)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func errTooMuchParams(maxArgs, argCount int) (err error) {
|
||||
err = fmt.Errorf("too much params -- expected %d, got %d", maxArgs, argCount)
|
||||
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 %T to %s", funcName, value, kind)
|
||||
if typer, ok := value.(Typer); ok {
|
||||
return fmt.Errorf("%s(): can't convert %s to %s", funcName, typer.TypeName(), kind)
|
||||
} else {
|
||||
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)
|
||||
}
|
||||
|
||||
func errDivisionByZero(funcName string) error {
|
||||
return fmt.Errorf("%s() division by zero", funcName)
|
||||
func errFuncDivisionByZero(funcName string) error {
|
||||
return fmt.Errorf("%s(): division by zero", funcName)
|
||||
}
|
||||
|
||||
func errDivisionByZero() error {
|
||||
return fmt.Errorf("division by zero")
|
||||
}
|
||||
|
||||
// --- Parameter errors
|
||||
|
||||
Reference in New Issue
Block a user