diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-12-03 12:10:18 -0800 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-12-03 12:10:18 -0800 |
commit | b4e9577f9b1cf9c29e106af3287a01f90dbac790 (patch) | |
tree | 8ff1026cc699316ea130cfdb6487b54010d96a8c /activerecord/lib/active_record | |
parent | 9329f28c6df6103e90f87aa2eae8cfb3bba88623 (diff) | |
parent | f606153755eb2498ccb8d87b72bbd6f3f848ed2f (diff) | |
download | rails-b4e9577f9b1cf9c29e106af3287a01f90dbac790.tar.gz rails-b4e9577f9b1cf9c29e106af3287a01f90dbac790.tar.bz2 rails-b4e9577f9b1cf9c29e106af3287a01f90dbac790.zip |
Merge pull request #12462 from jjb/improve_ar_exception_message_formatting
Improve formatting of ActiveRecord migration exception messages
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index f7e0a388d7..7d7e97e6c9 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -2,40 +2,47 @@ require "active_support/core_ext/module/attribute_accessors" require 'set' module ActiveRecord + class MigrationError < ActiveRecordError#:nodoc: + def initialize(message = nil) + message = "\n\n#{message}\n\n" if message + super + end + end + # Exception that can be raised to stop migrations from going backwards. - class IrreversibleMigration < ActiveRecordError + class IrreversibleMigration < MigrationError end - class DuplicateMigrationVersionError < ActiveRecordError#:nodoc: + class DuplicateMigrationVersionError < MigrationError#:nodoc: def initialize(version) super("Multiple migrations have the version number #{version}") end end - class DuplicateMigrationNameError < ActiveRecordError#:nodoc: + class DuplicateMigrationNameError < MigrationError#:nodoc: def initialize(name) super("Multiple migrations have the name #{name}") end end - class UnknownMigrationVersionError < ActiveRecordError #:nodoc: + class UnknownMigrationVersionError < MigrationError #:nodoc: def initialize(version) super("No migration with version number #{version}") end end - class IllegalMigrationNameError < ActiveRecordError#:nodoc: + class IllegalMigrationNameError < MigrationError#:nodoc: def initialize(name) super("Illegal name for migration file: #{name}\n\t(only lower case letters, numbers, and '_' allowed)") end end - class PendingMigrationError < ActiveRecordError#:nodoc: + class PendingMigrationError < MigrationError#:nodoc: def initialize if defined?(Rails) - super("Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=#{::Rails.env}' to resolve this issue.") + super("Migrations are pending. To resolve this issue, run:\n\n\tbin/rake db:migrate RAILS_ENV=#{::Rails.env}") else - super("Migrations are pending; run 'bin/rake db:migrate' to resolve this issue.") + super("Migrations are pending. To resolve this issue, run:\n\n\tbin/rake db:migrate") end end end |