45
39

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsの例外の一覧を得るワンライナー

Posted at

rails console などで以下を実行。

getRailsExceptionClasses
ObjectSpace.each_object(Class).select{|k| k.ancestors.include?(ActiveRecord::ActiveRecordError) }

結果:

=> [ActiveRecord::ConnectionTimeoutError,
 ActiveRecord::DeleteRestrictionError,
 ActiveRecord::ReadOnlyAssociation,
 ActiveRecord::EagerLoadPolymorphicError,
 ActiveRecord::HasAndBelongsToManyAssociationForeignKeyNeeded,
 ActiveRecord::HasManyThroughNestedAssociationsAreReadonly,
 ActiveRecord::HasManyThroughCantDissociateNewRecords,
 ActiveRecord::HasManyThroughCantAssociateNewRecords,
 ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection,
 ActiveRecord::HasManyThroughSourceAssociationNotFoundError,
 ActiveRecord::HasOneThroughCantAssociateThroughCollection,
 ActiveRecord::HasManyThroughAssociationPointlessSourceTypeError,
 ActiveRecord::HasManyThroughAssociationPolymorphicThroughError,
 ActiveRecord::HasManyThroughAssociationPolymorphicSourceError,
 ActiveRecord::HasManyThroughAssociationNotFoundError,
 ActiveRecord::InverseOfAssociationNotFoundError,
 ActiveRecord::RecordInvalid,
 ActiveRecord::NestedAttributes::TooManyRecords,
 ActiveRecord::Transactions::TransactionError,
 ActiveRecord::UnknownPrimaryKey,
 ActiveRecord::MultiparameterAssignmentErrors,
 ActiveRecord::AttributeAssignmentError,
 ActiveRecord::DangerousAttributeError,
 ActiveRecord::Rollback,
 ActiveRecord::ReadOnlyRecord,
 ActiveRecord::ConfigurationError,
 ActiveRecord::StaleObjectError,
 ActiveRecord::PreparedStatementInvalid,
 ActiveRecord::InvalidForeignKey,
 ActiveRecord::RecordNotUnique,
 ActiveRecord::WrappedDatabaseException,
 ActiveRecord::ThrowResult,
 ActiveRecord::StatementInvalid,
 ActiveRecord::RecordNotSaved,
 ActiveRecord::RecordNotFound,
 ActiveRecord::ConnectionNotEstablished,
 ActiveRecord::AdapterNotFound,
 ActiveRecord::AdapterNotSpecified,
 ActiveRecord::SerializationTypeMismatch,
 ActiveRecord::AssociationTypeMismatch,
 ActiveRecord::SubclassNotFound,
 ActiveRecord::ActiveRecordError]

参考: Getting a list of existing Rails Error classes for re-use/inheritance - Stack Overflow

45
39
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
45
39

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?