2022-08-18 01:16:43 +02:00
|
|
|
package maxminddb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
)
|
|
|
|
|
|
|
|
// InvalidDatabaseError is returned when the database contains invalid data
|
|
|
|
// and cannot be parsed.
|
|
|
|
type InvalidDatabaseError struct {
|
|
|
|
message string
|
|
|
|
}
|
|
|
|
|
|
|
|
func newOffsetError() InvalidDatabaseError {
|
|
|
|
return InvalidDatabaseError{"unexpected end of database"}
|
|
|
|
}
|
|
|
|
|
2023-07-13 22:34:10 +02:00
|
|
|
func newInvalidDatabaseError(format string, args ...any) InvalidDatabaseError {
|
2022-08-18 01:16:43 +02:00
|
|
|
return InvalidDatabaseError{fmt.Sprintf(format, args...)}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e InvalidDatabaseError) Error() string {
|
|
|
|
return e.message
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalTypeError is returned when the value in the database cannot be
|
|
|
|
// assigned to the specified data type.
|
|
|
|
type UnmarshalTypeError struct {
|
2023-07-13 22:34:10 +02:00
|
|
|
Type reflect.Type
|
|
|
|
Value string
|
2022-08-18 01:16:43 +02:00
|
|
|
}
|
|
|
|
|
2024-07-14 14:40:59 +02:00
|
|
|
func newUnmarshalTypeStrError(value string, rType reflect.Type) UnmarshalTypeError {
|
2022-08-18 01:16:43 +02:00
|
|
|
return UnmarshalTypeError{
|
|
|
|
Type: rType,
|
2024-07-14 14:40:59 +02:00
|
|
|
Value: value,
|
2022-08-18 01:16:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-14 14:40:59 +02:00
|
|
|
func newUnmarshalTypeError(value any, rType reflect.Type) UnmarshalTypeError {
|
|
|
|
return newUnmarshalTypeStrError(fmt.Sprintf("%v (%T)", value, value), rType)
|
|
|
|
}
|
|
|
|
|
2022-08-18 01:16:43 +02:00
|
|
|
func (e UnmarshalTypeError) Error() string {
|
2024-07-14 14:40:59 +02:00
|
|
|
return fmt.Sprintf("maxminddb: cannot unmarshal %s into type %s", e.Value, e.Type)
|
2022-08-18 01:16:43 +02:00
|
|
|
}
|