Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 173 lines (148 sloc) 6.474 kB
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored
1 module ActiveRecord
c869154 @rizwanreza Adds title.
rizwanreza authored
2
3 # = Active Record Errors
4 #
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored
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
33 # Raised when adapter not specified on connection (or configuration file <tt>config/database.yml</tt>
1ce40ca @neerajdotname ensuring that description does not exceed 100 columns
neerajdotname authored
34 # misses adapter field).
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored
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
42 # Raised when connection to the database could not been established (for example when <tt>connection=</tt>
1ce40ca @neerajdotname ensuring that description does not exceed 100 columns
neerajdotname authored
43 # is given a nil object).
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored
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
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
56 # Raised when SQL statement cannot be executed by the database (for example, it's often the case for
1ce40ca @neerajdotname ensuring that description does not exceed 100 columns
neerajdotname authored
57 # MySQL when Ruby driver used is too old).
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored
58 class StatementInvalid < ActiveRecordError
59 end
60
61 # Raised when SQL statement is invalid and the application gets a blank result.
62 class ThrowResult < ActiveRecordError
63 end
64
65 # Parent class for all specific exceptions which wrap database driver exceptions
66 # provides access to the original exception also.
67 class WrappedDatabaseException < StatementInvalid
68 attr_reader :original_exception
69
70 def initialize(message, original_exception)
71 super(message)
72 @original_exception = original_exception
73 end
74 end
75
76 # Raised when a record cannot be inserted because it would violate a uniqueness constraint.
77 class RecordNotUnique < WrappedDatabaseException
78 end
79
80 # Raised when a record cannot be inserted or updated because it references a non-existent record.
81 class InvalidForeignKey < WrappedDatabaseException
82 end
83
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
84 # Raised when number of bind variables in statement given to <tt>:condition</tt> key (for example,
1ce40ca @neerajdotname ensuring that description does not exceed 100 columns
neerajdotname authored
85 # when using +find+ method)
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored
86 # does not match number of expected variables.
87 #
88 # For example, in
89 #
4d4819f @amatsuda :conditions => where
amatsuda authored
90 # Location.where("lat = ? AND lng = ?", 53.7362)
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored
91 #
92 # two placeholders are given but only one variable to fill them.
93 class PreparedStatementInvalid < ActiveRecordError
94 end
95
96 # Raised on attempt to save stale record. Record is stale when it's being saved in another query after
97 # instantiation, for example, when two users edit the same wiki page and one starts editing and saves
98 # the page before the other.
99 #
100 # Read more about optimistic locking in ActiveRecord::Locking module RDoc.
101 class StaleObjectError < ActiveRecordError
102 end
103
104 # Raised when association is being configured improperly or
105 # user tries to use offset and limit together with has_many or has_and_belongs_to_many associations.
106 class ConfigurationError < ActiveRecordError
107 end
108
109 # Raised on attempt to update record that is instantiated as read only.
110 class ReadOnlyRecord < ActiveRecordError
111 end
112
113 # ActiveRecord::Transactions::ClassMethods.transaction uses this exception
114 # to distinguish a deliberate rollback from other exceptional situations.
115 # Normally, raising an exception will cause the +transaction+ method to rollback
116 # the database transaction *and* pass on the exception. But if you raise an
117 # ActiveRecord::Rollback exception, then the database transaction will be rolled back,
118 # without passing on the exception.
119 #
120 # For example, you could do this in your controller to rollback a transaction:
121 #
122 # class BooksController < ActionController::Base
123 # def create
124 # Book.transaction do
125 # book = Book.new(params[:book])
126 # book.save!
127 # if today_is_friday?
128 # # The system must fail on Friday so that our support department
129 # # won't be out of job. We silently rollback this transaction
130 # # without telling the user.
131 # raise ActiveRecord::Rollback, "Call tech support!"
132 # end
133 # end
134 # # ActiveRecord::Rollback is the only exception that won't be passed on
135 # # by ActiveRecord::Base.transaction, so this line will still be reached
136 # # even on Friday.
137 # redirect_to root_url
138 # end
139 # end
140 class Rollback < ActiveRecordError
141 end
142
143 # Raised when attribute has a name reserved by Active Record (when attribute has name of one of Active Record instance methods).
144 class DangerousAttributeError < ActiveRecordError
145 end
146
147 # Raised when unknown attributes are supplied via mass assignment.
148 class UnknownAttributeError < NoMethodError
149 end
150
151 # Raised when an error occurred while doing a mass assignment to an attribute through the
152 # <tt>attributes=</tt> method. The exception has an +attribute+ property that is the name of the
153 # offending attribute.
154 class AttributeAssignmentError < ActiveRecordError
155 attr_reader :exception, :attribute
156 def initialize(message, exception, attribute)
157 @exception = exception
158 @attribute = attribute
159 @message = message
160 end
161 end
162
163 # Raised when there are multiple errors while doing a mass assignment through the +attributes+
164 # method. The exception has an +errors+ property that contains an array of AttributeAssignmentError
165 # objects, each corresponding to the error while assigning to an attribute.
166 class MultiparameterAssignmentErrors < ActiveRecordError
167 attr_reader :errors
168 def initialize(errors)
169 @errors = errors
170 end
171 end
1ce40ca @neerajdotname ensuring that description does not exceed 100 columns
neerajdotname authored
172 end
Something went wrong with that request. Please try again.