psycopg2/lib/errors.py
Daniele Varrazzo 1bb3d5cfe2 Dropped duplicate classes in errors module
Also using a more compact class registration using a decorator
2018-10-23 00:31:57 +01:00

1315 lines
20 KiB
Python

"""Error classes for PostgreSQL error codes
"""
# Imported for completeness, but unused in this module.
from psycopg2._psycopg import Error, Warning, InterfaceError # noqa
from psycopg2._psycopg import (
DataError, DatabaseError, ProgrammingError, IntegrityError,
InternalError, NotSupportedError, OperationalError,
QueryCanceledError, TransactionRollbackError)
def lookup(code):
"""Lookup an error code and return its exception class.
Raise `!KeyError` if the code is not found.
"""
return _by_sqlstate[code]
_by_sqlstate = {}
def for_sqlstate(state):
def for_sqlstate_(cls):
_by_sqlstate[state] = cls
return cls
return for_sqlstate_
# autogenerated data: do not edit below this point.
# Class 02 - No Data (this is also a warning class per the SQL standard)
@for_sqlstate('02000')
class NoData(DatabaseError):
pass
@for_sqlstate('02001')
class NoAdditionalDynamicResultSetsReturned(DatabaseError):
pass
# Class 03 - SQL Statement Not Yet Complete
@for_sqlstate('03000')
class SqlStatementNotYetComplete(DatabaseError):
pass
# Class 08 - Connection Exception
@for_sqlstate('08000')
class ConnectionException(DatabaseError):
pass
@for_sqlstate('08001')
class SqlclientUnableToEstablishSqlconnection(DatabaseError):
pass
@for_sqlstate('08003')
class ConnectionDoesNotExist(DatabaseError):
pass
@for_sqlstate('08004')
class SqlserverRejectedEstablishmentOfSqlconnection(DatabaseError):
pass
@for_sqlstate('08006')
class ConnectionFailure(DatabaseError):
pass
@for_sqlstate('08007')
class TransactionResolutionUnknown(DatabaseError):
pass
@for_sqlstate('08P01')
class ProtocolViolation(DatabaseError):
pass
# Class 09 - Triggered Action Exception
@for_sqlstate('09000')
class TriggeredActionException(DatabaseError):
pass
# Class 0A - Feature Not Supported
@for_sqlstate('0A000')
class FeatureNotSupported(NotSupportedError):
pass
# Class 0B - Invalid Transaction Initiation
@for_sqlstate('0B000')
class InvalidTransactionInitiation(DatabaseError):
pass
# Class 0F - Locator Exception
@for_sqlstate('0F000')
class LocatorException(DatabaseError):
pass
@for_sqlstate('0F001')
class InvalidLocatorSpecification(DatabaseError):
pass
# Class 0L - Invalid Grantor
@for_sqlstate('0L000')
class InvalidGrantor(DatabaseError):
pass
@for_sqlstate('0LP01')
class InvalidGrantOperation(DatabaseError):
pass
# Class 0P - Invalid Role Specification
@for_sqlstate('0P000')
class InvalidRoleSpecification(DatabaseError):
pass
# Class 0Z - Diagnostics Exception
@for_sqlstate('0Z000')
class DiagnosticsException(DatabaseError):
pass
@for_sqlstate('0Z002')
class StackedDiagnosticsAccessedWithoutActiveHandler(DatabaseError):
pass
# Class 20 - Case Not Found
@for_sqlstate('20000')
class CaseNotFound(ProgrammingError):
pass
# Class 21 - Cardinality Violation
@for_sqlstate('21000')
class CardinalityViolation(ProgrammingError):
pass
# Class 22 - Data Exception
@for_sqlstate('22000')
class DataException(DataError):
pass
@for_sqlstate('22001')
class StringDataRightTruncation(DataError):
pass
@for_sqlstate('22002')
class NullValueNoIndicatorParameter(DataError):
pass
@for_sqlstate('22003')
class NumericValueOutOfRange(DataError):
pass
@for_sqlstate('22004')
class NullValueNotAllowed(DataError):
pass
@for_sqlstate('22005')
class ErrorInAssignment(DataError):
pass
@for_sqlstate('22007')
class InvalidDatetimeFormat(DataError):
pass
@for_sqlstate('22008')
class DatetimeFieldOverflow(DataError):
pass
@for_sqlstate('22009')
class InvalidTimeZoneDisplacementValue(DataError):
pass
@for_sqlstate('2200B')
class EscapeCharacterConflict(DataError):
pass
@for_sqlstate('2200C')
class InvalidUseOfEscapeCharacter(DataError):
pass
@for_sqlstate('2200D')
class InvalidEscapeOctet(DataError):
pass
@for_sqlstate('2200F')
class ZeroLengthCharacterString(DataError):
pass
@for_sqlstate('2200G')
class MostSpecificTypeMismatch(DataError):
pass
@for_sqlstate('2200H')
class SequenceGeneratorLimitExceeded(DataError):
pass
@for_sqlstate('2200L')
class NotAnXmlDocument(DataError):
pass
@for_sqlstate('2200M')
class InvalidXmlDocument(DataError):
pass
@for_sqlstate('2200N')
class InvalidXmlContent(DataError):
pass
@for_sqlstate('2200S')
class InvalidXmlComment(DataError):
pass
@for_sqlstate('2200T')
class InvalidXmlProcessingInstruction(DataError):
pass
@for_sqlstate('22010')
class InvalidIndicatorParameterValue(DataError):
pass
@for_sqlstate('22011')
class SubstringError(DataError):
pass
@for_sqlstate('22012')
class DivisionByZero(DataError):
pass
@for_sqlstate('22013')
class InvalidPrecedingOrFollowingSize(DataError):
pass
@for_sqlstate('22014')
class InvalidArgumentForNtileFunction(DataError):
pass
@for_sqlstate('22015')
class IntervalFieldOverflow(DataError):
pass
@for_sqlstate('22016')
class InvalidArgumentForNthValueFunction(DataError):
pass
@for_sqlstate('22018')
class InvalidCharacterValueForCast(DataError):
pass
@for_sqlstate('22019')
class InvalidEscapeCharacter(DataError):
pass
@for_sqlstate('2201B')
class InvalidRegularExpression(DataError):
pass
@for_sqlstate('2201E')
class InvalidArgumentForLogarithm(DataError):
pass
@for_sqlstate('2201F')
class InvalidArgumentForPowerFunction(DataError):
pass
@for_sqlstate('2201G')
class InvalidArgumentForWidthBucketFunction(DataError):
pass
@for_sqlstate('2201W')
class InvalidRowCountInLimitClause(DataError):
pass
@for_sqlstate('2201X')
class InvalidRowCountInResultOffsetClause(DataError):
pass
@for_sqlstate('22021')
class CharacterNotInRepertoire(DataError):
pass
@for_sqlstate('22022')
class IndicatorOverflow(DataError):
pass
@for_sqlstate('22023')
class InvalidParameterValue(DataError):
pass
@for_sqlstate('22024')
class UnterminatedCString(DataError):
pass
@for_sqlstate('22025')
class InvalidEscapeSequence(DataError):
pass
@for_sqlstate('22026')
class StringDataLengthMismatch(DataError):
pass
@for_sqlstate('22027')
class TrimError(DataError):
pass
@for_sqlstate('2202E')
class ArraySubscriptError(DataError):
pass
@for_sqlstate('2202G')
class InvalidTablesampleRepeat(DataError):
pass
@for_sqlstate('2202H')
class InvalidTablesampleArgument(DataError):
pass
@for_sqlstate('22P01')
class FloatingPointException(DataError):
pass
@for_sqlstate('22P02')
class InvalidTextRepresentation(DataError):
pass
@for_sqlstate('22P03')
class InvalidBinaryRepresentation(DataError):
pass
@for_sqlstate('22P04')
class BadCopyFileFormat(DataError):
pass
@for_sqlstate('22P05')
class UntranslatableCharacter(DataError):
pass
@for_sqlstate('22P06')
class NonstandardUseOfEscapeCharacter(DataError):
pass
# Class 23 - Integrity Constraint Violation
@for_sqlstate('23000')
class IntegrityConstraintViolation(IntegrityError):
pass
@for_sqlstate('23001')
class RestrictViolation(IntegrityError):
pass
@for_sqlstate('23502')
class NotNullViolation(IntegrityError):
pass
@for_sqlstate('23503')
class ForeignKeyViolation(IntegrityError):
pass
@for_sqlstate('23505')
class UniqueViolation(IntegrityError):
pass
@for_sqlstate('23514')
class CheckViolation(IntegrityError):
pass
@for_sqlstate('23P01')
class ExclusionViolation(IntegrityError):
pass
# Class 24 - Invalid Cursor State
@for_sqlstate('24000')
class InvalidCursorState(InternalError):
pass
# Class 25 - Invalid Transaction State
@for_sqlstate('25000')
class InvalidTransactionState(InternalError):
pass
@for_sqlstate('25001')
class ActiveSqlTransaction(InternalError):
pass
@for_sqlstate('25002')
class BranchTransactionAlreadyActive(InternalError):
pass
@for_sqlstate('25003')
class InappropriateAccessModeForBranchTransaction(InternalError):
pass
@for_sqlstate('25004')
class InappropriateIsolationLevelForBranchTransaction(InternalError):
pass
@for_sqlstate('25005')
class NoActiveSqlTransactionForBranchTransaction(InternalError):
pass
@for_sqlstate('25006')
class ReadOnlySqlTransaction(InternalError):
pass
@for_sqlstate('25007')
class SchemaAndDataStatementMixingNotSupported(InternalError):
pass
@for_sqlstate('25008')
class HeldCursorRequiresSameIsolationLevel(InternalError):
pass
@for_sqlstate('25P01')
class NoActiveSqlTransaction(InternalError):
pass
@for_sqlstate('25P02')
class InFailedSqlTransaction(InternalError):
pass
@for_sqlstate('25P03')
class IdleInTransactionSessionTimeout(InternalError):
pass
# Class 26 - Invalid SQL Statement Name
@for_sqlstate('26000')
class InvalidSqlStatementName(OperationalError):
pass
# Class 27 - Triggered Data Change Violation
@for_sqlstate('27000')
class TriggeredDataChangeViolation(OperationalError):
pass
# Class 28 - Invalid Authorization Specification
@for_sqlstate('28000')
class InvalidAuthorizationSpecification(OperationalError):
pass
@for_sqlstate('28P01')
class InvalidPassword(OperationalError):
pass
# Class 2B - Dependent Privilege Descriptors Still Exist
@for_sqlstate('2B000')
class DependentPrivilegeDescriptorsStillExist(InternalError):
pass
@for_sqlstate('2BP01')
class DependentObjectsStillExist(InternalError):
pass
# Class 2D - Invalid Transaction Termination
@for_sqlstate('2D000')
class InvalidTransactionTermination(InternalError):
pass
# Class 2F - SQL Routine Exception
@for_sqlstate('2F000')
class SqlRoutineException(InternalError):
pass
@for_sqlstate('2F002')
class ModifyingSqlDataNotPermitted(InternalError):
pass
@for_sqlstate('2F003')
class ProhibitedSqlStatementAttempted(InternalError):
pass
@for_sqlstate('2F004')
class ReadingSqlDataNotPermitted(InternalError):
pass
@for_sqlstate('2F005')
class FunctionExecutedNoReturnStatement(InternalError):
pass
# Class 34 - Invalid Cursor Name
@for_sqlstate('34000')
class InvalidCursorName(OperationalError):
pass
# Class 38 - External Routine Exception
@for_sqlstate('38000')
class ExternalRoutineException(InternalError):
pass
@for_sqlstate('38001')
class ContainingSqlNotPermitted(InternalError):
pass
@for_sqlstate('38002')
class ModifyingSqlDataNotPermittedExt(InternalError):
pass
@for_sqlstate('38003')
class ProhibitedSqlStatementAttemptedExt(InternalError):
pass
@for_sqlstate('38004')
class ReadingSqlDataNotPermittedExt(InternalError):
pass
# Class 39 - External Routine Invocation Exception
@for_sqlstate('39000')
class ExternalRoutineInvocationException(InternalError):
pass
@for_sqlstate('39001')
class InvalidSqlstateReturned(InternalError):
pass
@for_sqlstate('39004')
class NullValueNotAllowedExt(InternalError):
pass
@for_sqlstate('39P01')
class TriggerProtocolViolated(InternalError):
pass
@for_sqlstate('39P02')
class SrfProtocolViolated(InternalError):
pass
@for_sqlstate('39P03')
class EventTriggerProtocolViolated(InternalError):
pass
# Class 3B - Savepoint Exception
@for_sqlstate('3B000')
class SavepointException(InternalError):
pass
@for_sqlstate('3B001')
class InvalidSavepointSpecification(InternalError):
pass
# Class 3D - Invalid Catalog Name
@for_sqlstate('3D000')
class InvalidCatalogName(ProgrammingError):
pass
# Class 3F - Invalid Schema Name
@for_sqlstate('3F000')
class InvalidSchemaName(ProgrammingError):
pass
# Class 40 - Transaction Rollback
@for_sqlstate('40000')
class TransactionRollback(TransactionRollbackError):
pass
@for_sqlstate('40001')
class SerializationFailure(TransactionRollbackError):
pass
@for_sqlstate('40002')
class TransactionIntegrityConstraintViolation(TransactionRollbackError):
pass
@for_sqlstate('40003')
class StatementCompletionUnknown(TransactionRollbackError):
pass
@for_sqlstate('40P01')
class DeadlockDetected(TransactionRollbackError):
pass
# Class 42 - Syntax Error or Access Rule Violation
@for_sqlstate('42000')
class SyntaxErrorOrAccessRuleViolation(ProgrammingError):
pass
@for_sqlstate('42501')
class InsufficientPrivilege(ProgrammingError):
pass
@for_sqlstate('42601')
class SyntaxError(ProgrammingError):
pass
@for_sqlstate('42602')
class InvalidName(ProgrammingError):
pass
@for_sqlstate('42611')
class InvalidColumnDefinition(ProgrammingError):
pass
@for_sqlstate('42622')
class NameTooLong(ProgrammingError):
pass
@for_sqlstate('42701')
class DuplicateColumn(ProgrammingError):
pass
@for_sqlstate('42702')
class AmbiguousColumn(ProgrammingError):
pass
@for_sqlstate('42703')
class UndefinedColumn(ProgrammingError):
pass
@for_sqlstate('42704')
class UndefinedObject(ProgrammingError):
pass
@for_sqlstate('42710')
class DuplicateObject(ProgrammingError):
pass
@for_sqlstate('42712')
class DuplicateAlias(ProgrammingError):
pass
@for_sqlstate('42723')
class DuplicateFunction(ProgrammingError):
pass
@for_sqlstate('42725')
class AmbiguousFunction(ProgrammingError):
pass
@for_sqlstate('42803')
class GroupingError(ProgrammingError):
pass
@for_sqlstate('42804')
class DatatypeMismatch(ProgrammingError):
pass
@for_sqlstate('42809')
class WrongObjectType(ProgrammingError):
pass
@for_sqlstate('42830')
class InvalidForeignKey(ProgrammingError):
pass
@for_sqlstate('42846')
class CannotCoerce(ProgrammingError):
pass
@for_sqlstate('42883')
class UndefinedFunction(ProgrammingError):
pass
@for_sqlstate('428C9')
class GeneratedAlways(ProgrammingError):
pass
@for_sqlstate('42939')
class ReservedName(ProgrammingError):
pass
@for_sqlstate('42P01')
class UndefinedTable(ProgrammingError):
pass
@for_sqlstate('42P02')
class UndefinedParameter(ProgrammingError):
pass
@for_sqlstate('42P03')
class DuplicateCursor(ProgrammingError):
pass
@for_sqlstate('42P04')
class DuplicateDatabase(ProgrammingError):
pass
@for_sqlstate('42P05')
class DuplicatePreparedStatement(ProgrammingError):
pass
@for_sqlstate('42P06')
class DuplicateSchema(ProgrammingError):
pass
@for_sqlstate('42P07')
class DuplicateTable(ProgrammingError):
pass
@for_sqlstate('42P08')
class AmbiguousParameter(ProgrammingError):
pass
@for_sqlstate('42P09')
class AmbiguousAlias(ProgrammingError):
pass
@for_sqlstate('42P10')
class InvalidColumnReference(ProgrammingError):
pass
@for_sqlstate('42P11')
class InvalidCursorDefinition(ProgrammingError):
pass
@for_sqlstate('42P12')
class InvalidDatabaseDefinition(ProgrammingError):
pass
@for_sqlstate('42P13')
class InvalidFunctionDefinition(ProgrammingError):
pass
@for_sqlstate('42P14')
class InvalidPreparedStatementDefinition(ProgrammingError):
pass
@for_sqlstate('42P15')
class InvalidSchemaDefinition(ProgrammingError):
pass
@for_sqlstate('42P16')
class InvalidTableDefinition(ProgrammingError):
pass
@for_sqlstate('42P17')
class InvalidObjectDefinition(ProgrammingError):
pass
@for_sqlstate('42P18')
class IndeterminateDatatype(ProgrammingError):
pass
@for_sqlstate('42P19')
class InvalidRecursion(ProgrammingError):
pass
@for_sqlstate('42P20')
class WindowingError(ProgrammingError):
pass
@for_sqlstate('42P21')
class CollationMismatch(ProgrammingError):
pass
@for_sqlstate('42P22')
class IndeterminateCollation(ProgrammingError):
pass
# Class 44 - WITH CHECK OPTION Violation
@for_sqlstate('44000')
class WithCheckOptionViolation(ProgrammingError):
pass
# Class 53 - Insufficient Resources
@for_sqlstate('53000')
class InsufficientResources(OperationalError):
pass
@for_sqlstate('53100')
class DiskFull(OperationalError):
pass
@for_sqlstate('53200')
class OutOfMemory(OperationalError):
pass
@for_sqlstate('53300')
class TooManyConnections(OperationalError):
pass
@for_sqlstate('53400')
class ConfigurationLimitExceeded(OperationalError):
pass
# Class 54 - Program Limit Exceeded
@for_sqlstate('54000')
class ProgramLimitExceeded(OperationalError):
pass
@for_sqlstate('54001')
class StatementTooComplex(OperationalError):
pass
@for_sqlstate('54011')
class TooManyColumns(OperationalError):
pass
@for_sqlstate('54023')
class TooManyArguments(OperationalError):
pass
# Class 55 - Object Not In Prerequisite State
@for_sqlstate('55000')
class ObjectNotInPrerequisiteState(OperationalError):
pass
@for_sqlstate('55006')
class ObjectInUse(OperationalError):
pass
@for_sqlstate('55P02')
class CantChangeRuntimeParam(OperationalError):
pass
@for_sqlstate('55P03')
class LockNotAvailable(OperationalError):
pass
# Class 57 - Operator Intervention
@for_sqlstate('57000')
class OperatorIntervention(OperationalError):
pass
@for_sqlstate('57014')
class QueryCanceled(QueryCanceledError):
pass
@for_sqlstate('57P01')
class AdminShutdown(OperationalError):
pass
@for_sqlstate('57P02')
class CrashShutdown(OperationalError):
pass
@for_sqlstate('57P03')
class CannotConnectNow(OperationalError):
pass
@for_sqlstate('57P04')
class DatabaseDropped(OperationalError):
pass
# Class 58 - System Error (errors external to PostgreSQL itself)
@for_sqlstate('58000')
class SystemError(OperationalError):
pass
@for_sqlstate('58030')
class IoError(OperationalError):
pass
@for_sqlstate('58P01')
class UndefinedFile(OperationalError):
pass
@for_sqlstate('58P02')
class DuplicateFile(OperationalError):
pass
# Class 72 - Snapshot Failure
@for_sqlstate('72000')
class SnapshotTooOld(DatabaseError):
pass
# Class F0 - Configuration File Error
@for_sqlstate('F0000')
class ConfigFileError(InternalError):
pass
@for_sqlstate('F0001')
class LockFileExists(InternalError):
pass
# Class HV - Foreign Data Wrapper Error (SQL/MED)
@for_sqlstate('HV000')
class FdwError(OperationalError):
pass
@for_sqlstate('HV001')
class FdwOutOfMemory(OperationalError):
pass
@for_sqlstate('HV002')
class FdwDynamicParameterValueNeeded(OperationalError):
pass
@for_sqlstate('HV004')
class FdwInvalidDataType(OperationalError):
pass
@for_sqlstate('HV005')
class FdwColumnNameNotFound(OperationalError):
pass
@for_sqlstate('HV006')
class FdwInvalidDataTypeDescriptors(OperationalError):
pass
@for_sqlstate('HV007')
class FdwInvalidColumnName(OperationalError):
pass
@for_sqlstate('HV008')
class FdwInvalidColumnNumber(OperationalError):
pass
@for_sqlstate('HV009')
class FdwInvalidUseOfNullPointer(OperationalError):
pass
@for_sqlstate('HV00A')
class FdwInvalidStringFormat(OperationalError):
pass
@for_sqlstate('HV00B')
class FdwInvalidHandle(OperationalError):
pass
@for_sqlstate('HV00C')
class FdwInvalidOptionIndex(OperationalError):
pass
@for_sqlstate('HV00D')
class FdwInvalidOptionName(OperationalError):
pass
@for_sqlstate('HV00J')
class FdwOptionNameNotFound(OperationalError):
pass
@for_sqlstate('HV00K')
class FdwReplyHandle(OperationalError):
pass
@for_sqlstate('HV00L')
class FdwUnableToCreateExecution(OperationalError):
pass
@for_sqlstate('HV00M')
class FdwUnableToCreateReply(OperationalError):
pass
@for_sqlstate('HV00N')
class FdwUnableToEstablishConnection(OperationalError):
pass
@for_sqlstate('HV00P')
class FdwNoSchemas(OperationalError):
pass
@for_sqlstate('HV00Q')
class FdwSchemaNotFound(OperationalError):
pass
@for_sqlstate('HV00R')
class FdwTableNotFound(OperationalError):
pass
@for_sqlstate('HV010')
class FdwFunctionSequenceError(OperationalError):
pass
@for_sqlstate('HV014')
class FdwTooManyHandles(OperationalError):
pass
@for_sqlstate('HV021')
class FdwInconsistentDescriptorInformation(OperationalError):
pass
@for_sqlstate('HV024')
class FdwInvalidAttributeValue(OperationalError):
pass
@for_sqlstate('HV090')
class FdwInvalidStringLengthOrBufferLength(OperationalError):
pass
@for_sqlstate('HV091')
class FdwInvalidDescriptorFieldIdentifier(OperationalError):
pass
# Class P0 - PL/pgSQL Error
@for_sqlstate('P0000')
class PlpgsqlError(InternalError):
pass
@for_sqlstate('P0001')
class RaiseException(InternalError):
pass
@for_sqlstate('P0002')
class NoDataFound(InternalError):
pass
@for_sqlstate('P0003')
class TooManyRows(InternalError):
pass
@for_sqlstate('P0004')
class AssertFailure(InternalError):
pass
# Class XX - Internal Error
@for_sqlstate('XX000')
class InternalError_(InternalError):
pass
@for_sqlstate('XX001')
class DataCorrupted(InternalError):
pass
@for_sqlstate('XX002')
class IndexCorrupted(InternalError):
pass