pgerror.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Package pgerror holds SQLSTATE metadata and sentinel errors shared by the
  2. // parser, executor, and protocol servers.
  3. package pgerror
  4. import (
  5. "errors"
  6. "fmt"
  7. )
  8. // SQLSTATE codes used by PizzaSQL's protocol and HTTP surfaces.
  9. const (
  10. CodeFeatureNotSupported = "0A000"
  11. CodeInvalidText = "22P02"
  12. CodeUniqueViolation = "23505"
  13. CodeForeignKeyViolation = "23503"
  14. CodeCheckViolation = "23514"
  15. CodeSerializationFailure = "40001"
  16. CodeSyntaxError = "42601"
  17. CodeInternalError = "XX000"
  18. )
  19. // ErrFeatureNotSupported marks SQL that PizzaSQL intentionally rejects instead
  20. // of accepting with different semantics. Protocol layers map it to SQLSTATE
  21. // 0A000 (feature_not_supported) rather than a generic syntax or internal error.
  22. var ErrFeatureNotSupported = errors.New("feature not supported")
  23. // Unsupported returns an error that wraps ErrFeatureNotSupported with a
  24. // client-facing explanation and migration hint.
  25. func Unsupported(format string, args ...interface{}) error {
  26. return fmt.Errorf("%w: %s", ErrFeatureNotSupported, fmt.Sprintf(format, args...))
  27. }
  28. // ErrInvalidText marks input that is valid SQL but not valid text for the
  29. // target type, such as a malformed array literal. Protocol layers map it to
  30. // SQLSTATE 22P02 (invalid_text_representation).
  31. var ErrInvalidText = errors.New("invalid text representation")
  32. // InvalidText returns an error that wraps ErrInvalidText with a client-facing
  33. // explanation of the rejected input.
  34. func InvalidText(format string, args ...interface{}) error {
  35. return fmt.Errorf("%w: %s", ErrInvalidText, fmt.Sprintf(format, args...))
  36. }