From 355fd47c62dfd7d1e51b60a56ff4ec5ad7c83cf4 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 22 Aug 2025 19:24:01 +1200 Subject: [PATCH] Update app/controllers/general.php Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- app/controllers/general.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index ba59050881..a4f89d14c7 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -624,8 +624,8 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw if (\is_string($logs) && \strlen($logs) > $maxLogLength) { $warningMessage = "[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters.\n"; $warningLength = \strlen($warningMessage); - $maxContentLength = $maxLogLength - $warningLength; - $logs = $warningMessage . \substr($logs, -$maxContentLength); + $maxContentLength = max(0, $maxLogLength - $warningLength); + $logs = $warningMessage . ($maxContentLength > 0 ? \substr($logs, -$maxContentLength) : ''); } // Truncate errors if they exceed the limit @@ -635,10 +635,9 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw if (\is_string($errors) && \strlen($errors) > $maxErrorLength) { $warningMessage = "[WARNING] Errors truncated. The output exceeded {$maxErrorLength} characters.\n"; $warningLength = \strlen($warningMessage); - $maxContentLength = $maxErrorLength - $warningLength; - $errors = $warningMessage . \substr($errors, -$maxContentLength); + $maxContentLength = max(0, $maxErrorLength - $warningLength); + $errors = $warningMessage . ($maxContentLength > 0 ? \substr($errors, -$maxContentLength) : ''); } - /** Update execution status */ $status = $executionResponse['statusCode'] >= 500 ? 'failed' : 'completed'; $execution->setAttribute('status', $status);