From f606153755eb2498ccb8d87b72bbd6f3f848ed2f Mon Sep 17 00:00:00 2001
From: John Joseph Bachir <j@jjb.cc>
Date: Mon, 7 Oct 2013 21:25:35 -0400
Subject: ActiveRecord migration exception message formatting

---
 activerecord/lib/active_record/migration.rb | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

(limited to 'activerecord/lib')

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
-- 
cgit v1.2.3