No documentation for error classes

Issue #237 on hold
John Smart
created an issue

I can't find any documentation enumerating or describing error classes. This makes it pretty difficult to know how to handle connection issues and other runtime gotchas.

There's PG::Error but then in connection_spec.rb there's PG::UnableToSend but I don't see anywhere in source or docs that this is mentioned.

Comments (4)

  1. Michael Granger repo owner

    While I agree with you that this is important and would make it much easier to find exception types and what they mean, it's also a significant undertaking. I may get some time to do this over the summer, but it's not going to happen soon, so in the meantime we'd happily accept a patch for it!

  2. Michael Granger repo owner

    I forgot to mention: the list of error codes to exception classes is in PG::ERROR_CLASSES, keyed by code, so you can do something like this to make your own reference:

    PG::ERROR_CLASSES.each {|code, errclass| puts "%8s: %p" % [code, errclass] }
    

    which for my version of PostgreSQL and Ruby yields:

       03000: PG::SqlStatementNotYetComplete
          03: PG::SqlStatementNotYetComplete
       08000: PG::ConnectionException
          08: PG::ConnectionException
       08003: PG::ConnectionDoesNotExist
       08006: PG::ConnectionFailure
       08001: PG::SqlclientUnableToEstablishSqlconnection
       08004: PG::SqlserverRejectedEstablishmentOfSqlconnection
       08007: PG::TransactionResolutionUnknown
       08P01: PG::ProtocolViolation
       09000: PG::TriggeredActionException
          09: PG::TriggeredActionException
       0A000: PG::FeatureNotSupported
          0A: PG::FeatureNotSupported
       0B000: PG::InvalidTransactionInitiation
          0B: PG::InvalidTransactionInitiation
       0F000: PG::LocatorException
          0F: PG::LocatorException
       0F001: PG::LEInvalidSpecification
       0L000: PG::InvalidGrantor
          0L: PG::InvalidGrantor
       0LP01: PG::InvalidGrantOperation
       0P000: PG::InvalidRoleSpecification
          0P: PG::InvalidRoleSpecification
       0Z000: PG::DiagnosticsException
          0Z: PG::DiagnosticsException
       0Z002: PG::StackedDiagnosticsAccessedWithoutActiveHandler
       20000: PG::CaseNotFound
          20: PG::CaseNotFound
       21000: PG::CardinalityViolation
          21: PG::CardinalityViolation
       22000: PG::DataException
          22: PG::DataException
       2202E: PG::ArraySubscriptError
       22021: PG::CharacterNotInRepertoire
       22008: PG::DatetimeFieldOverflow
       22012: PG::DivisionByZero
       22005: PG::ErrorInAssignment
       2200B: PG::EscapeCharacterConflict
       22022: PG::IndicatorOverflow
       22015: PG::IntervalFieldOverflow
       2201E: PG::InvalidArgumentForLog
       22014: PG::InvalidArgumentForNtile
       22016: PG::InvalidArgumentForNthValue
       2201F: PG::InvalidArgumentForPowerFunction
       2201G: PG::InvalidArgumentForWidthBucketFunction
       22018: PG::InvalidCharacterValueForCast
       22007: PG::InvalidDatetimeFormat
       22019: PG::InvalidEscapeCharacter
       2200D: PG::InvalidEscapeOctet
       22025: PG::InvalidEscapeSequence
       22P06: PG::NonstandardUseOfEscapeCharacter
       22010: PG::InvalidIndicatorParameterValue
       22023: PG::InvalidParameterValue
       2201B: PG::InvalidRegularExpression
       2201W: PG::InvalidRowCountInLimitClause
       2201X: PG::InvalidRowCountInResultOffsetClause
       22009: PG::InvalidTimeZoneDisplacementValue
       2200C: PG::InvalidUseOfEscapeCharacter
       2200G: PG::MostSpecificTypeMismatch
       22004: PG::NullValueNotAllowed
       22002: PG::NullValueNoIndicatorParameter
       22003: PG::NumericValueOutOfRange
       22026: PG::StringDataLengthMismatch
       22001: PG::StringDataRightTruncation
       22011: PG::SubstringError
       22027: PG::TrimError
       22024: PG::UnterminatedCString
       2200F: PG::ZeroLengthCharacterString
       22P01: PG::FloatingPointException
       22P02: PG::InvalidTextRepresentation
       22P03: PG::InvalidBinaryRepresentation
       22P04: PG::BadCopyFileFormat
       22P05: PG::UntranslatableCharacter
       2200L: PG::NotAnXmlDocument
       2200M: PG::InvalidXmlDocument
       2200N: PG::InvalidXmlContent
       2200S: PG::InvalidXmlComment
       2200T: PG::InvalidXmlProcessingInstruction
       23000: PG::IntegrityConstraintViolation
          23: PG::IntegrityConstraintViolation
       23001: PG::RestrictViolation
       23502: PG::NotNullViolation
       23503: PG::ForeignKeyViolation
       23505: PG::UniqueViolation
       23514: PG::CheckViolation
       23P01: PG::ExclusionViolation
       24000: PG::InvalidCursorState
          24: PG::InvalidCursorState
       25000: PG::InvalidTransactionState
          25: PG::InvalidTransactionState
       25001: PG::ActiveSqlTransaction
       25002: PG::BranchTransactionAlreadyActive
       25008: PG::HeldCursorRequiresSameIsolationLevel
       25003: PG::InappropriateAccessModeForBranchTransaction
       25004: PG::InappropriateIsolationLevelForBranchTransaction
       25005: PG::NoActiveSqlTransactionForBranchTransaction
       25006: PG::ReadOnlySqlTransaction
       25007: PG::SchemaAndDataStatementMixingNotSupported
       25P01: PG::NoActiveSqlTransaction
       25P02: PG::InFailedSqlTransaction
       26000: PG::InvalidSqlStatementName
          26: PG::InvalidSqlStatementName
       27000: PG::TriggeredDataChangeViolation
          27: PG::TriggeredDataChangeViolation
       28000: PG::InvalidAuthorizationSpecification
          28: PG::InvalidAuthorizationSpecification
       28P01: PG::InvalidPassword
       2B000: PG::DependentPrivilegeDescriptorsStillExist
          2B: PG::DependentPrivilegeDescriptorsStillExist
       2BP01: PG::DependentObjectsStillExist
       2D000: PG::InvalidTransactionTermination
          2D: PG::InvalidTransactionTermination
       2F000: PG::SqlRoutineException
          2F: PG::SqlRoutineException
       2F005: PG::SREFunctionExecutedNoReturnStatement
       2F002: PG::SREModifyingSqlDataNotPermitted
       2F003: PG::SREProhibitedSqlStatementAttempted
       2F004: PG::SREReadingSqlDataNotPermitted
       34000: PG::InvalidCursorName
          34: PG::InvalidCursorName
       38000: PG::ExternalRoutineException
          38: PG::ExternalRoutineException
       38001: PG::EREContainingSqlNotPermitted
       38002: PG::EREModifyingSqlDataNotPermitted
       38003: PG::EREProhibitedSqlStatementAttempted
       38004: PG::EREReadingSqlDataNotPermitted
       39000: PG::ExternalRoutineInvocationException
          39: PG::ExternalRoutineInvocationException
       39001: PG::ERIEInvalidSqlstateReturned
       39004: PG::ERIENullValueNotAllowed
       39P01: PG::ERIETriggerProtocolViolated
       39P02: PG::ERIESrfProtocolViolated
       3B000: PG::SavepointException
          3B: PG::SavepointException
       3B001: PG::SEInvalidSpecification
       3D000: PG::InvalidCatalogName
          3D: PG::InvalidCatalogName
       3F000: PG::InvalidSchemaName
          3F: PG::InvalidSchemaName
       40000: PG::TransactionRollback
          40: PG::TransactionRollback
       40002: PG::TRIntegrityConstraintViolation
       40001: PG::TRSerializationFailure
       40003: PG::TRStatementCompletionUnknown
       40P01: PG::TRDeadlockDetected
       42000: PG::SyntaxErrorOrAccessRuleViolation
          42: PG::SyntaxErrorOrAccessRuleViolation
       42601: PG::SyntaxError
       42501: PG::InsufficientPrivilege
       42846: PG::CannotCoerce
       42803: PG::GroupingError
       42P20: PG::WindowingError
       42P19: PG::InvalidRecursion
       42830: PG::InvalidForeignKey
       42602: PG::InvalidName
       42622: PG::NameTooLong
       42939: PG::ReservedName
       42804: PG::DatatypeMismatch
       42P18: PG::IndeterminateDatatype
       42P21: PG::CollationMismatch
       42P22: PG::IndeterminateCollation
       42809: PG::WrongObjectType
       42703: PG::UndefinedColumn
       42883: PG::UndefinedFunction
       42P01: PG::UndefinedTable
       42P02: PG::UndefinedParameter
       42704: PG::UndefinedObject
       42701: PG::DuplicateColumn
       42P03: PG::DuplicateCursor
       42P04: PG::DuplicateDatabase
       42723: PG::DuplicateFunction
       42P05: PG::DuplicatePstatement
       42P06: PG::DuplicateSchema
       42P07: PG::DuplicateTable
       42712: PG::DuplicateAlias
       42710: PG::DuplicateObject
       42702: PG::AmbiguousColumn
       42725: PG::AmbiguousFunction
       42P08: PG::AmbiguousParameter
       42P09: PG::AmbiguousAlias
       42P10: PG::InvalidColumnReference
       42611: PG::InvalidColumnDefinition
       42P11: PG::InvalidCursorDefinition
       42P12: PG::InvalidDatabaseDefinition
       42P13: PG::InvalidFunctionDefinition
       42P14: PG::InvalidPstatementDefinition
       42P15: PG::InvalidSchemaDefinition
       42P16: PG::InvalidTableDefinition
       42P17: PG::InvalidObjectDefinition
       44000: PG::WithCheckOptionViolation
          44: PG::WithCheckOptionViolation
       53000: PG::InsufficientResources
          53: PG::InsufficientResources
       53100: PG::DiskFull
       53200: PG::OutOfMemory
       53300: PG::TooManyConnections
       53400: PG::ConfigurationLimitExceeded
       54000: PG::ProgramLimitExceeded
          54: PG::ProgramLimitExceeded
       54001: PG::StatementTooComplex
       54011: PG::TooManyColumns
       54023: PG::TooManyArguments
       55000: PG::ObjectNotInPrerequisiteState
          55: PG::ObjectNotInPrerequisiteState
       55006: PG::ObjectInUse
       55P02: PG::CantChangeRuntimeParam
       55P03: PG::LockNotAvailable
       57000: PG::OperatorIntervention
          57: PG::OperatorIntervention
       57014: PG::QueryCanceled
       57P01: PG::AdminShutdown
       57P02: PG::CrashShutdown
       57P03: PG::CannotConnectNow
       57P04: PG::DatabaseDropped
       58000: PG::SystemError
          58: PG::SystemError
       58030: PG::IoError
       58P01: PG::UndefinedFile
       58P02: PG::DuplicateFile
       F0000: PG::ConfigFileError
          F0: PG::ConfigFileError
       F0001: PG::LockFileExists
       HV000: PG::FdwError
          HV: PG::FdwError
       HV005: PG::FdwColumnNameNotFound
       HV002: PG::FdwDynamicParameterValueNeeded
       HV010: PG::FdwFunctionSequenceError
       HV021: PG::FdwInconsistentDescriptorInformation
       HV024: PG::FdwInvalidAttributeValue
       HV007: PG::FdwInvalidColumnName
       HV008: PG::FdwInvalidColumnNumber
       HV004: PG::FdwInvalidDataType
       HV006: PG::FdwInvalidDataTypeDescriptors
       HV091: PG::FdwInvalidDescriptorFieldIdentifier
       HV00B: PG::FdwInvalidHandle
       HV00C: PG::FdwInvalidOptionIndex
       HV00D: PG::FdwInvalidOptionName
       HV090: PG::FdwInvalidStringLengthOrBufferLength
       HV00A: PG::FdwInvalidStringFormat
       HV009: PG::FdwInvalidUseOfNullPointer
       HV014: PG::FdwTooManyHandles
       HV001: PG::FdwOutOfMemory
       HV00P: PG::FdwNoSchemas
       HV00J: PG::FdwOptionNameNotFound
       HV00K: PG::FdwReplyHandle
       HV00Q: PG::FdwSchemaNotFound
       HV00R: PG::FdwTableNotFound
       HV00L: PG::FdwUnableToCreateExecution
       HV00M: PG::FdwUnableToCreateReply
       HV00N: PG::FdwUnableToEstablishConnection
       P0000: PG::PlpgsqlError
          P0: PG::PlpgsqlError
       P0001: PG::RaiseException
       P0002: PG::NoDataFound
       P0003: PG::TooManyRows
       XX000: PG::InternalError
          XX: PG::InternalError
       XX001: PG::DataCorrupted
       XX002: PG::IndexCorrupted
    
  3. Log in to comment