goap/errors.go
2024-08-22 19:56:32 +02:00

63 lines
1.3 KiB
Go

package goap
import "fmt"
type NoRequiredFieldError struct {
FieldName string
}
func (n NoRequiredFieldError) Error() string {
return fmt.Sprintf("no attribute named %s", n.FieldName)
}
// Expected is a string representation of the expected type
type BadFieldValueError[T any] struct {
FieldName string
RawValue any
Expected T
}
func (b BadFieldValueError[T]) Error() string {
return fmt.Sprintf(
"attribute %s has a bad raw value, inspect error struct for raw and expected type",
b.FieldName,
)
}
type BadFieldArrayLengthError struct {
FieldName string
ExpectedLen int
ActualLen int
}
func (b BadFieldArrayLengthError) Error() string {
return fmt.Sprintf(
"attribute %s expects an array of length %d but got an array with %d elements",
b.FieldName,
b.ExpectedLen,
b.ActualLen,
)
}
type NoRequiredSubFieldError struct {
FieldName string
Subfield string
}
func (n NoRequiredSubFieldError) Error() string {
return fmt.Sprintf("missing subfield %s for attribute %s", n.Subfield, n.FieldName)
}
type NotImplementedError struct{}
func (n NotImplementedError) Error() string {
return "Feature not implemented yet"
}
type UnknownTagType struct {
TagType string
}
func (u UnknownTagType) Error() string {
return fmt.Sprintf("Unknown tag type: %s", u.TagType)
}