Skip to content

Commit 74ba54e

Browse files
mbardelmeijerMASNathan
authored andcommitted
Ensure that the PhantomJS command executes successfully (#71)
* Ensure that the PhantomJS command executes successfully * Validate on return code instead of anything was in the output
1 parent 3f5e578 commit 74ba54e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Capture.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Screen;
44

55
use Screen\Exceptions\InvalidArgumentException;
6+
use Screen\Exceptions\PhantomJsException;
67
use Screen\Exceptions\TemplateNotFoundException;
78
use Screen\Image\Types;
89
use Screen\Image\Types\Type;
@@ -225,7 +226,15 @@ public function save($imageLocation, $deleteFileIfExists = true)
225226
}
226227

227228
$command = sprintf("%sphantomjs %s %s", $this->binPath, $this->getOptionsString(), $jobPath);
228-
$result = exec(escapeshellcmd($command));
229+
230+
// Run the command and ensure it executes successfully
231+
$returnCode = null;
232+
$output = [];
233+
exec(sprintf("%s 2>&1", escapeshellcmd($command)), $output, $returnCode);
234+
235+
if ($returnCode !== 0) {
236+
throw new PhantomJsException($output);
237+
}
229238

230239
return file_exists($this->imageLocation);
231240
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Screen\Exceptions;
4+
5+
class PhantomJsException extends \Exception
6+
{
7+
public function __construct($message, $code = 0, \Exception $previous = null)
8+
{
9+
$message = is_array($message) ? implode(PHP_EOL, $message) : $message;
10+
11+
parent::__construct($message, $code, $previous);
12+
}
13+
}

0 commit comments

Comments
 (0)