merged branch schmittjoh/processFailedException (PR #3633)

Commits
-------

57de69f added an exception for failed processes

Discussion
----------

added an exception for failed processes

---------------------------------------------------------------------------

by Seldaek at 2012-03-19T07:27:56Z

So this is just there to use if you want to throw an exception when a process call failed in your application? It doesn't seem enabled by default, which I think is good anyway.

---------------------------------------------------------------------------

by stof at 2012-03-19T07:44:43Z

@Seldaek yeah, I guess this is a way to make it easier to reuse what he implemented for Assetic first.

---------------------------------------------------------------------------

by fabpot at 2012-03-23T15:08:26Z

How and when do you use such an exception?

---------------------------------------------------------------------------

by schmittjoh at 2012-03-23T17:22:16Z

It's intended for your own code to give you a nice and meaningful error message without having to repeat the same code whereever you are dealing with a Process:

```php
if (0 !== $proc->run()) {
    throw new ProcessFailedException($proc);
}
This commit is contained in:
Fabien Potencier 2012-03-23 19:56:05 +01:00
commit d5090ee044
3 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,21 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Exception;
/**
* Marker Interface for the Process Component.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
interface ExceptionInterface
{
}

View File

@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Exception;
use Symfony\Component\Process\Process;
/**
* Exception for failed processes.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class ProcessFailedException extends RuntimeException
{
private $process;
public function __construct(Process $process)
{
if ($process->isSuccessful()) {
throw new \InvalidArgumentException('Expected a failed process, but the given process was successful.');
}
parent::__construct(sprintf('The command "%s" failed.'."\n\nOutput:\n================\n".$process->getOutput()."\n\nError Output:\n================\n".$process->getErrorOutput()));
$this->process = $process;
}
public function getProcess()
{
return $this->process;
}
}

View File

@ -0,0 +1,21 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Exception;
/**
* RuntimeException for the Process Component.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}