Skip to content
This repository
Newer
Older
100644 212 lines (180 sloc) 7.685 kb
39d6f9e1 » wycats
2010-03-07 Make many parts of Rails lazy. In order to facilitate this,
1 module ActiveRecord
c8691545 » rizwanreza
2010-06-15 Adds title.
2
3 # = Active Record Errors
4 #
39d6f9e1 » wycats
2010-03-07 Make many parts of Rails lazy. In order to facilitate this,
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.
890da514 » AvnerCohen
2012-11-10 1.9 Syntax related changes
25 # @ticket.patches << Comment.new(content: "Please attach tests to your patch.")
39d6f9e1 » wycats
2010-03-07 Make many parts of Rails lazy. In order to facilitate this,
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
b451de0d » spastorino
2010-08-14 Deletes trailing whitespaces (over text files only find * -type f -ex…
33 # Raised when adapter not specified on connection (or configuration file <tt>config/database.yml</tt>
1ce40ca5 » neerajdotname
2010-08-02 ensuring that description does not exceed 100 columns
34 # misses adapter field).
39d6f9e1 » wycats
2010-03-07 Make many parts of Rails lazy. In order to facilitate this,
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
b451de0d » spastorino
2010-08-14 Deletes trailing whitespaces (over text files only find * -type f -ex…
42 # Raised when connection to the database could not been established (for example when <tt>connection=</tt>
1ce40ca5 » neerajdotname
2010-08-02 ensuring that description does not exceed 100 columns
43 # is given a nil object).
39d6f9e1 » wycats
2010-03-07 Make many parts of Rails lazy. In order to facilitate this,
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
4faaa811 » marcandre
2012-06-05 + ActiveRecord::Base#destroy!
56 # Raised by ActiveRecord::Base.destroy! when a call to destroy would return false.
57 class RecordNotDestroyed < ActiveRecordError
58 end
59
b451de0d » spastorino
2010-08-14 Deletes trailing whitespaces (over text files only find * -type f -ex…
60 # Raised when SQL statement cannot be executed by the database (for example, it's often the case for
1ce40ca5 » neerajdotname
2010-08-02 ensuring that description does not exceed 100 columns
61 # MySQL when Ruby driver used is too old).
39d6f9e1 » wycats
2010-03-07 Make many parts of Rails lazy. In order to facilitate this,
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
b451de0d » spastorino
2010-08-14 Deletes trailing whitespaces (over text files only find * -type f -ex…
88 # Raised when number of bind variables in statement given to <tt>:condition</tt> key (for example,
1ce40ca5 » neerajdotname
2010-08-02 ensuring that description does not exceed 100 columns
89 # when using +find+ method)
39d6f9e1 » wycats
2010-03-07 Make many parts of Rails lazy. In order to facilitate this,
90 # does not match number of expected variables.
91 #
92 # For example, in
93 #
4d4819fb » amatsuda
2011-07-08 :conditions => where
94 # Location.where("lat = ? AND lng = ?", 53.7362)
39d6f9e1 » wycats
2010-03-07 Make many parts of Rails lazy. In order to facilitate this,
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
c6f0461e » fabrik42
2011-10-14 Consider attempted action in exception message of ActiveRecord::Stale…
106 attr_reader :record, :attempted_action
410fa4cf » fabrik42
2011-10-14 Includes stale record in StaleObjectError
107
c6f0461e » fabrik42
2011-10-14 Consider attempted action in exception message of ActiveRecord::Stale…
108 def initialize(record, attempted_action)
ab7c1c4e » mauricio
2012-06-27 Fixes #6825, adds tests covering cases and error possibilities, also …
109 super("Attempted to #{attempted_action} a stale object: #{record.class.name}")
410fa4cf » fabrik42
2011-10-14 Includes stale record in StaleObjectError
110 @record = record
c6f0461e » fabrik42
2011-10-14 Consider attempted action in exception message of ActiveRecord::Stale…
111 @attempted_action = attempted_action
410fa4cf » fabrik42
2011-10-14 Includes stale record in StaleObjectError
112 end
113
39d6f9e1 » wycats
2010-03-07 Make many parts of Rails lazy. In order to facilitate this,
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)
ab7c1c4e » mauricio
2012-06-27 Fixes #6825, adds tests covering cases and error possibilities, also …
169 super(message)
39d6f9e1 » wycats
2010-03-07 Make many parts of Rails lazy. In order to facilitate this,
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
2e9e647f » jonleighton
2011-10-05 Raise an exception on unknown primary key inside AssociationReflection.
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)
ab7c1c4e » mauricio
2012-06-27 Fixes #6825, adds tests covering cases and error possibilities, also …
190 super("Unknown primary key for table #{model.table_name} in model #{model}.")
2e9e647f » jonleighton
2011-10-05 Raise an exception on unknown primary key inside AssociationReflection.
191 @model = model
192 end
193
194 end
70d36257 » jonleighton
2012-06-22 disallow mutating a relation once loaded
195
7a36dc73 » frodsan
2012-10-26 update AR::ImmutableRelation documentation [ci skip]
196 # Raised when a relation cannot be mutated because it's already loaded.
197 #
198 # class Task < ActiveRecord::Base
199 # end
200 #
201 # relation = Task.all
202 # relation.loaded? # => true
203 #
ee917493 » vijaydev
2012-11-03 copy edits [ci skip]
204 # # Methods which try to mutate a loaded relation fail.
205 # relation.where!(title: 'TODO') # => ActiveRecord::ImmutableRelation
206 # relation.limit!(5) # => ActiveRecord::ImmutableRelation
70d36257 » jonleighton
2012-06-22 disallow mutating a relation once loaded
207 class ImmutableRelation < ActiveRecordError
208 end
392eeecc » jonleighton
2012-09-21 Support for specifying transaction isolation level
209
210 class TransactionIsolationError < ActiveRecordError
211 end
1ce40ca5 » neerajdotname
2010-08-02 ensuring that description does not exceed 100 columns
212 end
Something went wrong with that request. Please try again.