Skip to content

Commit 01b38e3

Browse files
author
Josias Castro
committed
capture JasperStarter errors and include them in ErrorCommandExecutable exception message
1 parent c11525c commit 01b38e3

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/Exception/ErrorCommandExecutable.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,21 @@ class ErrorCommandExecutable extends Exception
1111
* @param string $message
1212
* @param int $code
1313
* @param Exception|null $previous
14+
* @param array $output
15+
*
1416
*/
15-
public function __construct($message = "", $code = 0, Exception $previous = null)
17+
public function __construct($message = "", $code = 0, Exception $previous = null, $output = [])
1618
{
17-
$message = 'Your report has an error and couldn \'t be processed!\ Try to output the command using the function `output();` and run it manually in the console.';
19+
$message = '';
20+
21+
foreach ($output as $line) {
22+
$message .= $line . ' ';
23+
}
24+
25+
if (empty($message)) {
26+
$message = 'Your report has an error and couldn\'t be processed! Try to output the command using the function `output();` and run it manually in the console.';
27+
}
28+
1829
parent::__construct($message, $code, $previous);
1930
}
2031
}

src/PHPJasper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
class PHPJasper
3131
{
32-
3332
/**
3433
* @var string
3534
*/
@@ -173,6 +172,8 @@ public function process(string $input, string $output, array $options = [])
173172
$this->command .= " -r {$options['resources']}";
174173
}
175174

175+
$this->command .= " 2>&1";
176+
176177
return $this;
177178
}
178179

@@ -247,7 +248,7 @@ public function execute($user = false)
247248
exec($this->command, $output, $returnVar);
248249

249250
if ($returnVar !== 0) {
250-
throw new Exception\ErrorCommandExecutable();
251+
throw new Exception\ErrorCommandExecutable(null, null, null, $output);
251252
}
252253

253254
return $output;

0 commit comments

Comments
 (0)