diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php
index 60ac50508..9ad0d1308 100644
--- a/src/Composer/Console/Application.php
+++ b/src/Composer/Console/Application.php
@@ -27,6 +27,7 @@ use Composer\IO\IOInterface;
use Composer\IO\ConsoleIO;
use Composer\Json\JsonValidationException;
use Composer\Util\ErrorHandler;
+use Composer\EventDispatcher\ScriptExecutionException;
/**
* The console application that handles the commands
@@ -217,6 +218,8 @@ class Application extends BaseApplication
}
return $result;
+ } catch (ScriptExecutionException $e) {
+ return $e->getCode();
} catch (\Exception $e) {
$this->hintCommonErrors($e);
throw $e;
diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php
index 358b03181..7d473c4ad 100644
--- a/src/Composer/EventDispatcher/EventDispatcher.php
+++ b/src/Composer/EventDispatcher/EventDispatcher.php
@@ -181,9 +181,9 @@ class EventDispatcher
}
$exec = $phpPath . ' ' . realpath($_SERVER['argv'][0]) . substr($callable, 9);
if (0 !== ($exitCode = $this->process->execute($exec))) {
- $this->io->writeError(sprintf('Script %s handling the %s event returned with an error', $callable, $event->getName()));
+ $this->io->writeError(sprintf('Script %s handling the %s event returned with error code '.$exitCode.'', $callable, $event->getName()));
- throw new \RuntimeException('Error Output: '.$this->process->getErrorOutput(), $exitCode);
+ throw new ScriptExecutionException('Error Output: '.$this->process->getErrorOutput(), $exitCode);
}
} else {
if (!$this->getListeners(new Event($scriptName))) {
@@ -221,9 +221,9 @@ class EventDispatcher
$this->io->writeError(sprintf('> %s', $exec));
}
if (0 !== ($exitCode = $this->process->execute($exec))) {
- $this->io->writeError(sprintf('Script %s handling the %s event returned with an error', $callable, $event->getName()));
+ $this->io->writeError(sprintf('Script %s handling the %s event returned with error code '.$exitCode.'', $callable, $event->getName()));
- throw new \RuntimeException('Error Output: '.$this->process->getErrorOutput(), $exitCode);
+ throw new ScriptExecutionException('Error Output: '.$this->process->getErrorOutput(), $exitCode);
}
}
diff --git a/src/Composer/EventDispatcher/ScriptExecutionException.php b/src/Composer/EventDispatcher/ScriptExecutionException.php
new file mode 100644
index 000000000..2b12ff68d
--- /dev/null
+++ b/src/Composer/EventDispatcher/ScriptExecutionException.php
@@ -0,0 +1,20 @@
+
+ * Jordi Boggiano
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\EventDispatcher;
+
+/**
+ * @author Jordi Boggiano
+ */
+class ScriptExecutionException extends \RuntimeException
+{
+}