errors.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package maxminddb
  2. import (
  3. "fmt"
  4. "reflect"
  5. )
  6. // InvalidDatabaseError is returned when the database contains invalid data
  7. // and cannot be parsed.
  8. type InvalidDatabaseError struct {
  9. message string
  10. }
  11. func newInvalidDatabaseError(format string, args ...interface{}) InvalidDatabaseError {
  12. return InvalidDatabaseError{fmt.Sprintf(format, args...)}
  13. }
  14. func (e InvalidDatabaseError) Error() string {
  15. return e.message
  16. }
  17. // UnmarshalTypeError is returned when the value in the database cannot be
  18. // assigned to the specified data type.
  19. type UnmarshalTypeError struct {
  20. Value string // stringified copy of the database value that caused the error
  21. Type reflect.Type // type of the value that could not be assign to
  22. }
  23. func newUnmarshalTypeError(value interface{}, rType reflect.Type) UnmarshalTypeError {
  24. return UnmarshalTypeError{
  25. Value: fmt.Sprintf("%v", value),
  26. Type: rType,
  27. }
  28. }
  29. func (e UnmarshalTypeError) Error() string {
  30. return fmt.Sprintf("maxminddb: cannot unmarshal %s into type %s", e.Value, e.Type.String())
  31. }