Skip to content
Newer
Older
100644 199 lines (167 sloc) 7.05 KB
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
1 module ActiveRecord
c869154 @rizwanreza Adds title.
rizwanreza authored Jun 15, 2010
2
3 # = Active Record Errors
4 #
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
5 # Generic Active Record exception class.
6 class ActiveRecordError < StandardError
7 end
8
9 # Raised when the single-table inheritance mechanism fails to locate the subclass
10 # (for example due to improper usage of column that +inheritance_column+ points to).
11 class SubclassNotFound < ActiveRecordError #:nodoc:
12 end
13
14 # Raised when an object assigned to an association has an incorrect type.
15 #
16 # class Ticket < ActiveRecord::Base
17 # has_many :patches
18 # end
19 #
20 # class Patch < ActiveRecord::Base
21 # belongs_to :ticket
22 # end
23 #
24 # # Comments are not patches, this assignment raises AssociationTypeMismatch.
25 # @ticket.patches << Comment.new(:content => "Please attach tests to your patch.")
26 class AssociationTypeMismatch < ActiveRecordError
27 end
28
29 # Raised when unserialized object's type mismatches one specified for serializable field.
30 class SerializationTypeMismatch < ActiveRecordError
31 end
32
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
33 # Raised when adapter not specified on connection (or configuration file <tt>config/database.yml</tt>
1ce40ca ensuring that description does not exceed 100 columns
Neeraj Singh authored Aug 2, 2010
34 # misses adapter field).
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
35 class AdapterNotSpecified < ActiveRecordError
36 end
37
38 # Raised when Active Record cannot find database adapter specified in <tt>config/database.yml</tt> or programmatically.
39 class AdapterNotFound < ActiveRecordError
40 end
41
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
42 # Raised when connection to the database could not been established (for example when <tt>connection=</tt>
1ce40ca ensuring that description does not exceed 100 columns
Neeraj Singh authored Aug 2, 2010
43 # is given a nil object).
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
44 class ConnectionNotEstablished < ActiveRecordError
45 end
46
47 # Raised when Active Record cannot find record by given id or set of ids.
48 class RecordNotFound < ActiveRecordError
49 end
50
51 # Raised by ActiveRecord::Base.save! and ActiveRecord::Base.create! methods when record cannot be
52 # saved because record is invalid.
53 class RecordNotSaved < ActiveRecordError
54 end
55
4faaa81 @marcandre + ActiveRecord::Base#destroy!
marcandre authored Jun 5, 2012
56 # Raised by ActiveRecord::Base.destroy! when a call to destroy would return false.
57 class RecordNotDestroyed < ActiveRecordError
58 end
59
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
60 # Raised when SQL statement cannot be executed by the database (for example, it's often the case for
1ce40ca ensuring that description does not exceed 100 columns
Neeraj Singh authored Aug 2, 2010
61 # MySQL when Ruby driver used is too old).
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
62 class StatementInvalid < ActiveRecordError
63 end
64
65 # Raised when SQL statement is invalid and the application gets a blank result.
66 class ThrowResult < ActiveRecordError
67 end
68
69 # Parent class for all specific exceptions which wrap database driver exceptions
70 # provides access to the original exception also.
71 class WrappedDatabaseException < StatementInvalid
72 attr_reader :original_exception
73
74 def initialize(message, original_exception)
75 super(message)
76 @original_exception = original_exception
77 end
78 end
79
80 # Raised when a record cannot be inserted because it would violate a uniqueness constraint.
81 class RecordNotUnique < WrappedDatabaseException
82 end
83
84 # Raised when a record cannot be inserted or updated because it references a non-existent record.
85 class InvalidForeignKey < WrappedDatabaseException
86 end
87
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
88 # Raised when number of bind variables in statement given to <tt>:condition</tt> key (for example,
1ce40ca ensuring that description does not exceed 100 columns
Neeraj Singh authored Aug 2, 2010
89 # when using +find+ method)
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
90 # does not match number of expected variables.
91 #
92 # For example, in
93 #
4d4819f @amatsuda :conditions => where
amatsuda authored Jul 8, 2011
94 # Location.where("lat = ? AND lng = ?", 53.7362)
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
95 #
96 # two placeholders are given but only one variable to fill them.
97 class PreparedStatementInvalid < ActiveRecordError
98 end
99
100 # Raised on attempt to save stale record. Record is stale when it's being saved in another query after
101 # instantiation, for example, when two users edit the same wiki page and one starts editing and saves
102 # the page before the other.
103 #
104 # Read more about optimistic locking in ActiveRecord::Locking module RDoc.
105 class StaleObjectError < ActiveRecordError
c6f0461 @fabrik42 Consider attempted action in exception message of ActiveRecord::Stale…
fabrik42 authored Oct 14, 2011
106 attr_reader :record, :attempted_action
410fa4c @fabrik42 Includes stale record in StaleObjectError
fabrik42 authored Oct 14, 2011
107
c6f0461 @fabrik42 Consider attempted action in exception message of ActiveRecord::Stale…
fabrik42 authored Oct 14, 2011
108 def initialize(record, attempted_action)
ab7c1c4 @mauricio Fixes #6825, adds tests covering cases and error possibilities, also …
mauricio authored Jun 27, 2012
109 super("Attempted to #{attempted_action} a stale object: #{record.class.name}")
410fa4c @fabrik42 Includes stale record in StaleObjectError
fabrik42 authored Oct 14, 2011
110 @record = record
c6f0461 @fabrik42 Consider attempted action in exception message of ActiveRecord::Stale…
fabrik42 authored Oct 14, 2011
111 @attempted_action = attempted_action
410fa4c @fabrik42 Includes stale record in StaleObjectError
fabrik42 authored Oct 14, 2011
112 end
113
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
114 end
115
116 # Raised when association is being configured improperly or
117 # user tries to use offset and limit together with has_many or has_and_belongs_to_many associations.
118 class ConfigurationError < ActiveRecordError
119 end
120
121 # Raised on attempt to update record that is instantiated as read only.
122 class ReadOnlyRecord < ActiveRecordError
123 end
124
125 # ActiveRecord::Transactions::ClassMethods.transaction uses this exception
126 # to distinguish a deliberate rollback from other exceptional situations.
127 # Normally, raising an exception will cause the +transaction+ method to rollback
128 # the database transaction *and* pass on the exception. But if you raise an
129 # ActiveRecord::Rollback exception, then the database transaction will be rolled back,
130 # without passing on the exception.
131 #
132 # For example, you could do this in your controller to rollback a transaction:
133 #
134 # class BooksController < ActionController::Base
135 # def create
136 # Book.transaction do
137 # book = Book.new(params[:book])
138 # book.save!
139 # if today_is_friday?
140 # # The system must fail on Friday so that our support department
141 # # won't be out of job. We silently rollback this transaction
142 # # without telling the user.
143 # raise ActiveRecord::Rollback, "Call tech support!"
144 # end
145 # end
146 # # ActiveRecord::Rollback is the only exception that won't be passed on
147 # # by ActiveRecord::Base.transaction, so this line will still be reached
148 # # even on Friday.
149 # redirect_to root_url
150 # end
151 # end
152 class Rollback < ActiveRecordError
153 end
154
155 # Raised when attribute has a name reserved by Active Record (when attribute has name of one of Active Record instance methods).
156 class DangerousAttributeError < ActiveRecordError
157 end
158
159 # Raised when unknown attributes are supplied via mass assignment.
160 class UnknownAttributeError < NoMethodError
161 end
162
163 # Raised when an error occurred while doing a mass assignment to an attribute through the
164 # <tt>attributes=</tt> method. The exception has an +attribute+ property that is the name of the
165 # offending attribute.
166 class AttributeAssignmentError < ActiveRecordError
167 attr_reader :exception, :attribute
168 def initialize(message, exception, attribute)
ab7c1c4 @mauricio Fixes #6825, adds tests covering cases and error possibilities, also …
mauricio authored Jun 27, 2012
169 super(message)
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
170 @exception = exception
171 @attribute = attribute
172 end
173 end
174
175 # Raised when there are multiple errors while doing a mass assignment through the +attributes+
176 # method. The exception has an +errors+ property that contains an array of AttributeAssignmentError
177 # objects, each corresponding to the error while assigning to an attribute.
178 class MultiparameterAssignmentErrors < ActiveRecordError
179 attr_reader :errors
180 def initialize(errors)
181 @errors = errors
182 end
183 end
2e9e647 @jonleighton Raise an exception on unknown primary key inside AssociationReflection.
jonleighton authored Oct 5, 2011
184
185 # Raised when a primary key is needed, but there is not one specified in the schema or model.
186 class UnknownPrimaryKey < ActiveRecordError
187 attr_reader :model
188
189 def initialize(model)
ab7c1c4 @mauricio Fixes #6825, adds tests covering cases and error possibilities, also …
mauricio authored Jun 27, 2012
190 super("Unknown primary key for table #{model.table_name} in model #{model}.")
2e9e647 @jonleighton Raise an exception on unknown primary key inside AssociationReflection.
jonleighton authored Oct 5, 2011
191 @model = model
192 end
193
194 end
70d3625 @jonleighton disallow mutating a relation once loaded
jonleighton authored Jun 22, 2012
195
196 class ImmutableRelation < ActiveRecordError
197 end
1ce40ca ensuring that description does not exceed 100 columns
Neeraj Singh authored Aug 2, 2010
198 end
Something went wrong with that request. Please try again.