From d8f1e555ce0a7025c5cd951c19a35476fabae002 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Sat, 30 Dec 2023 20:35:32 +0100 Subject: [PATCH] [FIX] Catch exception to prevent crash When the process fails with an exception the rendering should not stop. We just want to continue to the rendering. --- .../src/Graphs/Renderer/PlantumlRenderer.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/guides-graphs/src/Graphs/Renderer/PlantumlRenderer.php b/packages/guides-graphs/src/Graphs/Renderer/PlantumlRenderer.php index b1467d47a..f7055163a 100644 --- a/packages/guides-graphs/src/Graphs/Renderer/PlantumlRenderer.php +++ b/packages/guides-graphs/src/Graphs/Renderer/PlantumlRenderer.php @@ -14,6 +14,7 @@ namespace phpDocumentor\Guides\Graphs\Renderer; use Psr\Log\LoggerInterface; +use Symfony\Component\Process\Exception\RuntimeException; use Symfony\Component\Process\Process; use function file_get_contents; @@ -44,13 +45,17 @@ public function render(string $diagram): string|null $pumlFileLocation = tempnam(sys_get_temp_dir() . '/phpdocumentor', 'pu_'); file_put_contents($pumlFileLocation, $output); + try { + $process = new Process([$this->plantUmlBinaryPath, '-tsvg', $pumlFileLocation], __DIR__, null, null, 600.0); + $process->run(); - $process = new Process([$this->plantUmlBinaryPath, '-tsvg', $pumlFileLocation], __DIR__, null, null, 600.0); - $process->run(); - - if (!$process->isSuccessful()) { - $this->logger->error('Generating the class diagram failed', ['error' => $process->getErrorOutput()]); + if (!$process->isSuccessful()) { + $this->logger->error('Generating the class diagram failed', ['error' => $process->getErrorOutput()]); + return null; + } + } catch(RuntimeException $e) { + $this->logger->error('Generating the class diagram failed', ['error' => $e->getMessage()]); return null; }