1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
# frozen-string-literal: true
module Sequel
# The default exception class for exceptions raised by Sequel.
# All exception classes defined by Sequel are descendants of this class.
class Error < ::StandardError
# If this exception wraps an underlying exception, the underlying
# exception is held here.
attr_accessor :wrapped_exception
# :nocov:
if RUBY_VERSION >= '2.1'
# :nocov:
# Returned the wrapped exception if one exists, otherwise use
# ruby's default behavior.
def cause
wrapped_exception || super
end
end
end
(
# Error raised when there is a failed attempt to acquire an advisory lock.
AdvisoryLockError = Class.new(Error)
).name
(
# Error raised when the adapter requested doesn't exist or can't be loaded.
AdapterNotFound = Class.new(Error)
).name
(
# Generic error raised by the database adapters, indicating a
# problem originating from the database server. Usually raised
# because incorrect SQL syntax is used.
DatabaseError = Class.new(Error)
).name
(
# Error raised when the Sequel is unable to connect to the database with the
# connection parameters it was given.
DatabaseConnectionError = Class.new(DatabaseError)
).name
(
# Error raised by adapters when they determine that the connection
# to the database has been lost. Instructs the connection pool code to
# remove that connection from the pool so that other connections can be acquired
# automatically.
DatabaseDisconnectError = Class.new(DatabaseError)
).name
(
# Generic error raised when Sequel determines a database constraint has been violated.
ConstraintViolation = Class.new(DatabaseError)
).name
(
# Error raised when Sequel determines a database check constraint has been violated.
CheckConstraintViolation = Class.new(ConstraintViolation)
).name
(
# Error raised when Sequel determines a database foreign key constraint has been violated.
ForeignKeyConstraintViolation = Class.new(ConstraintViolation)
).name
(
# Error raised when Sequel determines a database NOT NULL constraint has been violated.
NotNullConstraintViolation = Class.new(ConstraintViolation)
).name
(
# Error raised when Sequel determines a database unique constraint has been violated.
UniqueConstraintViolation = Class.new(ConstraintViolation)
).name
(
# Error raised when Sequel determines a serialization failure/deadlock in the database.
SerializationFailure = Class.new(DatabaseError)
).name
(
# Error raised when Sequel determines the database could not acquire a necessary lock
# before timing out. Use of Dataset#nowait can often cause this exception when
# retrieving rows.
DatabaseLockTimeout = Class.new(DatabaseError)
).name
(
# Error raised on an invalid operation, such as trying to update or delete
# a joined or grouped dataset when the database does not support that.
InvalidOperation = Class.new(Error)
).name
(
# Error raised when attempting an invalid type conversion.
InvalidValue = Class.new(Error)
).name
# Error raised when the user requests a record via the first! or similar
# method, and the dataset does not yield any rows.
class NoMatchingRow < Error
# The dataset that raised this NoMatchingRow exception.
attr_accessor :dataset
# If the first argument is a Sequel::Dataset, set the dataset related to
# the exception to that argument, instead of assuming it is the exception message.
def initialize(msg=nil)
if msg.is_a?(Sequel::Dataset)
@dataset = msg
msg = nil
end
super
end
end
(
# Error raised when the connection pool cannot acquire a database connection
# before the timeout.
PoolTimeout = Class.new(Error)
).name
(
# Error that you should raise to signal a rollback of the current transaction.
# The transaction block will catch this exception, rollback the current transaction,
# and won't reraise it (unless a reraise is requested).
Rollback = Class.new(Error)
).name
end
|