From 604f63d39995cc44035463abf444c89528105ed9 Mon Sep 17 00:00:00 2001 From: Christian Hartmann Date: Mon, 9 Mar 2026 23:48:28 +0100 Subject: [PATCH] fix(export): Handle exceptions when reading file content and ignore whitespace-only files Signed-off-by: Christian Hartmann --- lib/Service/SubmissionService.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Service/SubmissionService.php b/lib/Service/SubmissionService.php index c171219bc..b80c96ece 100644 --- a/lib/Service/SubmissionService.php +++ b/lib/Service/SubmissionService.php @@ -380,9 +380,19 @@ function (array $carry, Answer $answer) use ($questionPerQuestionId, $gridRowsPe * @param list, label?: string, url?: string}|mixed|null|string>> $data */ private function exportData(array $header, array $data, string $fileFormat, ?File $file = null): string { - if ($file && $file->getContent()) { + $content = null; + if ($file) { + try { + $content = $file->getContent(); + } catch (\Exception $e) { + $this->logger->warning('Failed to read existing linked file content: {msg}', ['msg' => $e->getMessage()]); + } + } + + // Ignore whitespace-only files (e.g. S3 single-space placeholder). + if ($content !== null && trim($content) !== '') { $existentFile = $this->tempManager->getTemporaryFile($fileFormat); - file_put_contents($existentFile, $file->getContent()); + file_put_contents($existentFile, $content); $spreadsheet = IOFactory::load($existentFile); } else { $spreadsheet = new Spreadsheet();