From f47bce9bc846abb15c12c15518b6528aadeec2d9 Mon Sep 17 00:00:00 2001 From: Matt Button Date: Fri, 21 Jan 2011 00:45:35 +0000 Subject: [PATCH] Give more helpful error messages when a migration fails --- classes/minion/migration/exception.php | 33 ++++++++++++++++++++++ classes/minion/migration/manager.php | 10 ++++++- classes/minion/task/db/migrate.php | 14 +++++++-- views/minion/task/db/migrate/exception.php | 3 ++ 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 classes/minion/migration/exception.php create mode 100644 views/minion/task/db/migrate/exception.php diff --git a/classes/minion/migration/exception.php b/classes/minion/migration/exception.php new file mode 100644 index 0000000..0b8f38f --- /dev/null +++ b/classes/minion/migration/exception.php @@ -0,0 +1,33 @@ +_migration = $migration; + + parent::__construct($message, $variables, $code); + } + + /** + * Get the migration that caused this exception to be thrown + * + * @return array + */ + public function get_migration() + { + return $this->_migration; + } +} diff --git a/classes/minion/migration/manager.php b/classes/minion/migration/manager.php index 65ce8c0..77bea45 100644 --- a/classes/minion/migration/manager.php +++ b/classes/minion/migration/manager.php @@ -182,7 +182,15 @@ class Minion_Migration_Manager { $db = $this->_get_db_instance($instance->get_database_connection()); - $instance->$method($db); + try + { + $instance->$method($db); + } + catch(Database_Exception $e) + { + throw new Minion_Migration_Exception($e->getMessage(), $migration); + } + if($this->_dry_run) { diff --git a/classes/minion/task/db/migrate.php b/classes/minion/task/db/migrate.php index 16e83b3..75af87b 100644 --- a/classes/minion/task/db/migrate.php +++ b/classes/minion/task/db/migrate.php @@ -89,10 +89,20 @@ class Minion_Task_Db_Migrate extends Minion_Task // Sync the available migrations with those in the db ->sync_migration_files() - ->set_dry_run($dry_run) + ->set_dry_run($dry_run); + try + { // Run migrations for specified locations & versions - ->run_migration($locations, $targets, $this->_default_direction); + $manager->run_migration($locations, $targets, $this->_default_direction); + } + catch(Minion_Migration_Exception $e) + { + return View::factory('minion/task/db/migrate/exception') + ->set('migration', $e->get_migration()) + ->set('error', $e->getMessage()); + } + $view = View::factory('minion/task/db/migrate') ->set('dry_run', $dry_run) diff --git a/views/minion/task/db/migrate/exception.php b/views/minion/task/db/migrate/exception.php new file mode 100644 index 0000000..9a252f3 --- /dev/null +++ b/views/minion/task/db/migrate/exception.php @@ -0,0 +1,3 @@ +Minion encountered an error while executing migration `` (): + +