Skip to content

Commit 434b877

Browse files
authored
Merge pull request #794 from phpDocumentor/fix/prevent-graph-render-crash
[FIX] Catch exception to prevent crash
2 parents 2170c2a + 875f27f commit 434b877

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/guides-graphs/src/Graphs/Renderer/PlantumlRenderer.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace phpDocumentor\Guides\Graphs\Renderer;
1515

1616
use Psr\Log\LoggerInterface;
17+
use Symfony\Component\Process\Exception\RuntimeException;
1718
use Symfony\Component\Process\Process;
1819

1920
use function file_get_contents;
@@ -44,12 +45,17 @@ public function render(string $diagram): string|null
4445

4546
$pumlFileLocation = tempnam(sys_get_temp_dir() . '/phpdocumentor', 'pu_');
4647
file_put_contents($pumlFileLocation, $output);
48+
try {
49+
$process = new Process([$this->plantUmlBinaryPath, '-tsvg', $pumlFileLocation], __DIR__, null, null, 600.0);
50+
$process->run();
4751

48-
$process = new Process([$this->plantUmlBinaryPath, '-tsvg', $pumlFileLocation], __DIR__, null, null, 600.0);
49-
$process->run();
52+
if (!$process->isSuccessful()) {
53+
$this->logger->error('Generating the class diagram failed', ['error' => $process->getErrorOutput()]);
5054

51-
if (!$process->isSuccessful()) {
52-
$this->logger->error('Generating the class diagram failed', ['error' => $process->getErrorOutput()]);
55+
return null;
56+
}
57+
} catch (RuntimeException $e) {
58+
$this->logger->error('Generating the class diagram failed', ['error' => $e->getMessage()]);
5359

5460
return null;
5561
}

0 commit comments

Comments
 (0)