Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v3.0.0.beta.3
Fetching contributors…

Cannot retrieve contributors at this time

165 lines (142 sloc) 6.446 kb
module ActiveRecord
# Generic Active Record exception class.
class ActiveRecordError < StandardError
# Raised when the single-table inheritance mechanism fails to locate the subclass
# (for example due to improper usage of column that +inheritance_column+ points to).
class SubclassNotFound < ActiveRecordError #:nodoc:
# Raised when an object assigned to an association has an incorrect type.
# class Ticket < ActiveRecord::Base
# has_many :patches
# end
# class Patch < ActiveRecord::Base
# belongs_to :ticket
# end
# # Comments are not patches, this assignment raises AssociationTypeMismatch.
# @ticket.patches << => "Please attach tests to your patch.")
class AssociationTypeMismatch < ActiveRecordError
# Raised when unserialized object's type mismatches one specified for serializable field.
class SerializationTypeMismatch < ActiveRecordError
# Raised when adapter not specified on connection (or configuration file <tt>config/database.yml</tt> misses adapter field).
class AdapterNotSpecified < ActiveRecordError
# Raised when Active Record cannot find database adapter specified in <tt>config/database.yml</tt> or programmatically.
class AdapterNotFound < ActiveRecordError
# Raised when connection to the database could not been established (for example when <tt>connection=</tt> is given a nil object).
class ConnectionNotEstablished < ActiveRecordError
# Raised when Active Record cannot find record by given id or set of ids.
class RecordNotFound < ActiveRecordError
# Raised by! and ActiveRecord::Base.create! methods when record cannot be
# saved because record is invalid.
class RecordNotSaved < ActiveRecordError
# Raised when SQL statement cannot be executed by the database (for example, it's often the case for MySQL when Ruby driver used is too old).
class StatementInvalid < ActiveRecordError
# Raised when SQL statement is invalid and the application gets a blank result.
class ThrowResult < ActiveRecordError
# Parent class for all specific exceptions which wrap database driver exceptions
# provides access to the original exception also.
class WrappedDatabaseException < StatementInvalid
attr_reader :original_exception
def initialize(message, original_exception)
@original_exception = original_exception
# Raised when a record cannot be inserted because it would violate a uniqueness constraint.
class RecordNotUnique < WrappedDatabaseException
# Raised when a record cannot be inserted or updated because it references a non-existent record.
class InvalidForeignKey < WrappedDatabaseException
# Raised when number of bind variables in statement given to <tt>:condition</tt> key (for example, when using +find+ method)
# does not match number of expected variables.
# For example, in
# Location.find :all, :conditions => ["lat = ? AND lng = ?", 53.7362]
# two placeholders are given but only one variable to fill them.
class PreparedStatementInvalid < ActiveRecordError
# Raised on attempt to save stale record. Record is stale when it's being saved in another query after
# instantiation, for example, when two users edit the same wiki page and one starts editing and saves
# the page before the other.
# Read more about optimistic locking in ActiveRecord::Locking module RDoc.
class StaleObjectError < ActiveRecordError
# Raised when association is being configured improperly or
# user tries to use offset and limit together with has_many or has_and_belongs_to_many associations.
class ConfigurationError < ActiveRecordError
# Raised on attempt to update record that is instantiated as read only.
class ReadOnlyRecord < ActiveRecordError
# ActiveRecord::Transactions::ClassMethods.transaction uses this exception
# to distinguish a deliberate rollback from other exceptional situations.
# Normally, raising an exception will cause the +transaction+ method to rollback
# the database transaction *and* pass on the exception. But if you raise an
# ActiveRecord::Rollback exception, then the database transaction will be rolled back,
# without passing on the exception.
# For example, you could do this in your controller to rollback a transaction:
# class BooksController < ActionController::Base
# def create
# Book.transaction do
# book =[:book])
# if today_is_friday?
# # The system must fail on Friday so that our support department
# # won't be out of job. We silently rollback this transaction
# # without telling the user.
# raise ActiveRecord::Rollback, "Call tech support!"
# end
# end
# # ActiveRecord::Rollback is the only exception that won't be passed on
# # by ActiveRecord::Base.transaction, so this line will still be reached
# # even on Friday.
# redirect_to root_url
# end
# end
class Rollback < ActiveRecordError
# Raised when attribute has a name reserved by Active Record (when attribute has name of one of Active Record instance methods).
class DangerousAttributeError < ActiveRecordError
# Raised when unknown attributes are supplied via mass assignment.
class UnknownAttributeError < NoMethodError
# Raised when an error occurred while doing a mass assignment to an attribute through the
# <tt>attributes=</tt> method. The exception has an +attribute+ property that is the name of the
# offending attribute.
class AttributeAssignmentError < ActiveRecordError
attr_reader :exception, :attribute
def initialize(message, exception, attribute)
@exception = exception
@attribute = attribute
@message = message
# Raised when there are multiple errors while doing a mass assignment through the +attributes+
# method. The exception has an +errors+ property that contains an array of AttributeAssignmentError
# objects, each corresponding to the error while assigning to an attribute.
class MultiparameterAssignmentErrors < ActiveRecordError
attr_reader :errors
def initialize(errors)
@errors = errors
Jump to Line
Something went wrong with that request. Please try again.