pg-rethrow
v1.0.1
Published
Transform PostgreSQL errors into useful, custom Error types
Downloads
175
Readme
pg-rethrow
When PostgreSQL throws an error, most node clients surface this as an Error
instance with the data that Postgres returned. This includes a variety of
metadata, but most importantly an opaque code
property, e.g. 23502
.
Since this isn't very useful to humans, this library parses these codes and
throws custom errors (such as NotNullViolation
) that are a lot easier to work
with.
This is especially useful with libraries like Bluebird
that let you catch
custom errors individually.
Built for use with pg-promise, but should work with most PostgreSQL clients and ORMs.
Usage
$ npm install --save pg-rethrow
import rethrow from 'pg-rethrow';
DB.query('UPDATE...')
.catch(rethrow)
.catch(rethrow.ERRORS.NotNullViolation, (err) => {
console.log('Oh no! A Not Null violation!');
});
Wasn't that easy?
rethrow.ERRORS
contains an exhaustive list of error constructors (see below).
For the ones you're not interested in handling, you can generally ignore them
and let them fall through to your generic Error
handlers.
Development / Contributing
Pull Requests should pass tests (npm test
) and lint rules (npm run lint
).
List of Errors
ActiveSqlTransaction
AdminShutdown
AmbiguousAlias
AmbiguousColumn
AmbiguousFunction
AmbiguousParameter
ArraySubscriptError
BadCopyFileFormat
BranchTransactionAlreadyActive
CannotCoerce
CannotConnectNow
CantChangeRuntimeParam
CardinalityViolation
CaseNotFound
CharacterNotInRepertoire
CheckViolation
CollationMismatch
ConfigFileError
ConfigurationLimitExceeded
ConnectionDoesNotExist
ConnectionException
ConnectionFailure
ContainingSqlNotPermitted
CrashShutdown
DatabaseDropped
DataCorrupted
DataException
DatatypeMismatch
DatetimeFieldOverflow
DeadlockDetected
DependentObjectsStillExist
DependentPrivilegeDescriptorsStillExist
DeprecatedFeature
DiagnosticsException
DiskFull
DivisionByZero
DuplicateAlias
DuplicateColumn
DuplicateCursor
DuplicateDatabase
DuplicateFile
DuplicateFunction
DuplicateObject
DuplicatePreparedStatement
DuplicateSchema
DuplicateTable
DynamicResultSetsReturned
ErrorInAssignment
EscapeCharacterConflict
ExclusionViolation
ExternalRoutineException
ExternalRoutineInvocationException
FdwColumnNameNotFound
FdwDynamicParameterValueNeeded
FdwError
FdwFunctionSequenceError
FdwInconsistentDescriptorInformation
FdwInvalidAttributeValue
FdwInvalidColumnName
FdwInvalidColumnNumber
FdwInvalidDataType
FdwInvalidDataTypeDescriptors
FdwInvalidDescriptorFieldIdentifier
FdwInvalidHandle
FdwInvalidOptionIndex
FdwInvalidOptionName
FdwInvalidStringFormat
FdwInvalidStringLengthOrBufferLength
FdwInvalidUseOfNullPointer
FdwNoSchemas
FdwOptionNameNotFound
FdwOutOfMemory
FdwReplyHandle
FdwSchemaNotFound
FdwTableNotFound
FdwTooManyHandles
FdwUnableToCreateExecution
FdwUnableToCreateReply
FdwUnableToEstablishConnection
FeatureNotSupported
FloatingPointException
ForeignKeyViolation
FunctionExecutedNoReturnStatement
GroupingError
HeldCursorRequiresSameIsolationLevel
ImplicitZeroBitPadding
InappropriateAccessModeForBranchTransaction
InappropriateIsolationLevelForBranchTransaction
IndeterminateCollation
IndeterminateDatatype
IndexCorrupted
IndicatorOverflow
InFailedSqlTransaction
InsufficientPrivilege
InsufficientResources
IntegrityConstraintViolation
InternalError
IntervalFieldOverflow
InvalidArgumentForLogarithm
InvalidArgumentForNthValueFunction
InvalidArgumentForNtileFunction
InvalidArgumentForPowerFunction
InvalidArgumentForWidthBucketFunction
InvalidAuthorizationSpecification
InvalidBinaryRepresentation
InvalidCatalogName
InvalidCharacterValueForCast
InvalidColumnDefinition
InvalidColumnReference
InvalidCursorDefinition
InvalidCursorName
InvalidCursorState
InvalidDatabaseDefinition
InvalidDatetimeFormat
InvalidEscapeCharacter
InvalidEscapeOctet
InvalidEscapeSequence
InvalidForeignKey
InvalidFunctionDefinition
InvalidGrantOperation
InvalidGrantor
InvalidIndicatorParameterValue
InvalidLocatorSpecification
InvalidName
InvalidObjectDefinition
InvalidParameterValue
InvalidPassword
InvalidPreparedStatementDefinition
InvalidRecursion
InvalidRegularExpression
InvalidRoleSpecification
InvalidRowCountInLimitClause
InvalidRowCountInResultOffsetClause
InvalidSavepointSpecification
InvalidSchemaDefinition
InvalidSchemaName
InvalidSqlStatementName
InvalidSqlstateReturned
InvalidTableDefinition
InvalidTextRepresentation
InvalidTimeZoneDisplacementValue
InvalidTransactionInitiation
InvalidTransactionState
InvalidTransactionTermination
InvalidUseOfEscapeCharacter
InvalidXmlComment
InvalidXmlContent
InvalidXmlDocument
InvalidXmlProcessingInstruction
IoError
LocatorException
LockFileExists
LockNotAvailable
ModifyingSqlDataNotPermitted
ModifyingSqlDataNotPermitted
MostSpecificTypeMismatch
NameTooLong
NoActiveSqlTransaction
NoActiveSqlTransactionForBranchTransaction
NoAdditionalDynamicResultSetsReturned
NoData
NoDataFound
NonstandardUseOfEscapeCharacter
NotAnXmlDocument
NotNullViolation
NullValueEliminatedInSetFunction
NullValueNoIndicatorParameter
NullValueNotAllowed
NullValueNotAllowed
NumericValueOutOfRange
ObjectInUse
ObjectNotInPrerequisiteState
OperatorIntervention
OutOfMemory
PlpgsqlError
PrivilegeNotGranted
PrivilegeNotRevoked
ProgramLimitExceeded
ProhibitedSqlStatementAttempted
ProhibitedSqlStatementAttempted
ProtocolViolation
QueryCanceled
RaiseException
ReadingSqlDataNotPermitted
ReadingSqlDataNotPermitted
ReadOnlySqlTransaction
ReservedName
RestrictViolation
SavepointException
SchemaAndDataStatementMixingNotSupported
SerializationFailure
SqlclientUnableToEstablishSqlconnection
SqlRoutineException
SqlserverRejectedEstablishmentOfSqlconnection
SqlStatementNotYetComplete
SrfProtocolViolated
StackedDiagnosticsAccessedWithoutActiveHandler
StatementCompletionUnknown
StatementTooComplex
StringDataLengthMismatch
StringDataRightTruncation
StringDataRightTruncation
SubstringError
SuccessfulCompletion
SyntaxError
SyntaxErrorOrAccessRuleViolation
SystemError
TooManyArguments
TooManyColumns
TooManyConnections
TooManyRows
TransactionIntegrityConstraintViolation
TransactionResolutionUnknown
TransactionRollback
TriggeredActionException
TriggeredDataChangeViolation
TriggerProtocolViolated
TrimError
UndefinedColumn
UndefinedFile
UndefinedFunction
UndefinedObject
UndefinedParameter
UndefinedTable
UniqueViolation
UnterminatedCString
UntranslatableCharacter
Warning
WindowingError
WithCheckOptionViolation
WrongObjectType
ZeroLengthCharacterString