Permalink
Browse files

Show a proper error message when asked to execute an invalid task.

  • Loading branch information...
1 parent b758cd9 commit 26745d90a48ce49e93d670686e213be30bb8a624 @kiall kiall committed Mar 30, 2012
View
23 classes/Kohana/Minion/Exception/Handler.php → classes/Kohana/Minion/Exception.php
@@ -1,15 +1,14 @@
<?php defined('SYSPATH') or die('No direct script access.');
/**
- * Handles CLI exceptions
+ * Minipn exception
*
* @package Kohana
* @category Minion
* @author Kohana Team
* @copyright (c) 2009-2011 Kohana Team
* @license http://kohanaframework.org/license
*/
-class Kohana_Minion_Exception_Handler extends Kohana_Kohana_Exception {
-
+class Kohana_Minion_Exception extends Kohana_Exception {
/**
* Inline exception handler, displays the error message, source of the
* exception, and the stack trace of the error.
@@ -26,8 +25,17 @@ public static function handler(Exception $e)
{
try
{
- echo Kohana_Exception::text($e);
- exit($e->getCode());
+ echo $e->format_for_cli();
+
+ $exit_code = $e->getCode();
+
+ // Never exit "0" after an exception.
+ if ($exit_code == 0)
+ {
+ $exit_code = 1;
+ }
+
+ exit($exit_code);
}
catch (Exception $e)
{
@@ -41,4 +49,9 @@ public static function handler(Exception $e)
exit(1);
}
}
+
+ public function format_for_cli()
+ {
+ return Kohana_Exception::text($e);
+ }
}
View
18 classes/Kohana/Minion/Exception/InvalidTask.php
@@ -0,0 +1,18 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * Invalid Task Exception
+ *
+ * @package Kohana
+ * @category Minion
+ * @author Kohana Team
+ * @copyright (c) 2009-2011 Kohana Team
+ * @license http://kohanaframework.org/license
+ */
+class Kohana_Minion_Exception_InvalidTask extends Minion_Exception {
+
+ public function format_for_cli()
+ {
+ return 'ERROR: '. $this->getMessage().PHP_EOL;
+ }
+
+}
View
17 classes/Kohana/Minion/Task.php
@@ -52,9 +52,7 @@ public static function convert_class_to_task($class)
* Factory for loading minion tasks
*
* @param array An array of command line options. It should contain the 'task' key
- *
- * @throws Kohana_Exception
- *
+ * @throws Minion_Exception_InvalidTask
* @return Minion_Task The Minion task
*/
public static function factory($options)
@@ -76,15 +74,24 @@ public static function factory($options)
$class = Minion_Task::convert_task_to_class_name($task);
- if ( ! in_array('Minion_Task', class_parents($class)))
+ if ( ! class_exists($class))
{
- throw new Kohana_Exception(
+ throw new Minion_Exception_InvalidTask(
"Task ':task' is not a valid minion task",
array(':task' => $class)
);
}
$class = new $class;
+
+ if ( ! $class instanceof Minion_Task)
+ {
+ throw new Minion_Exception_InvalidTask(
+ "Task ':task' is not a valid minion task",
+ array(':task' => $class)
+ );
+ }
+
$class->set_options($options);
// Show the help page for this task if requested
View
3 classes/Minion/Exception.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Minion_Exception extends Kohana_Minion_Exception {}
View
3 classes/Minion/Exception/Handler.php
@@ -1,3 +0,0 @@
-<?php defined('SYSPATH') or die('No direct script access.');
-
-class Minion_Exception_Handler extends Kohana_Minion_Exception_Handler {}
View
3 classes/Minion/Exception/InvalidTask.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Minion_Exception_InvalidTask extends Kohana_Minion_Exception_InvalidTask {}

0 comments on commit 26745d9

Please sign in to comment.