package errs
import (
)
type OutOfRange struct {
What string
ValidLow string
ValidHigh string
Actual string
}
func ( OutOfRange) () string {
if .ValidHigh < .ValidLow {
return fmt.Sprintf(
"out of range: %v has no valid value, but is %v", .What, .Actual)
}
return fmt.Sprintf(
"out of range: %s must be from %s to %s, but is %s",
.What, .ValidLow, .ValidHigh, .Actual)
}
type BadValue struct {
What string
Valid string
Actual string
}
func ( BadValue) () string {
return fmt.Sprintf(
"bad value: %v must be %v, but is %v", .What, .Valid, .Actual)
}
type ArityMismatch struct {
What string
ValidLow int
ValidHigh int
Actual int
}
func ( ArityMismatch) () string {
switch {
case .ValidHigh == .ValidLow:
return fmt.Sprintf("arity mismatch: %v must be %v, but is %v",
.What, nValues(.ValidLow), nValues(.Actual))
case .ValidHigh == -1:
return fmt.Sprintf("arity mismatch: %v must be %v or more values, but is %v",
.What, .ValidLow, nValues(.Actual))
default:
return fmt.Sprintf("arity mismatch: %v must be %v to %v values, but is %v",
.What, .ValidLow, .ValidHigh, nValues(.Actual))
}
}
func ( int) string {
if == 1 {
return "1 value"
}
return strconv.Itoa() + " values"
}
type SetReadOnlyVar struct {
VarName string
}
func ( SetReadOnlyVar) () string {
return fmt.Sprintf("cannot set read-only variable %q", .VarName)
}