npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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