From 78ea003e6e08994f42acdbdad19ffae99cbd3d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kruli=C5=A1?= Date: Tue, 10 Dec 2024 23:46:53 +0100 Subject: [PATCH] Fixing bug - overflowing error strings in async jobs. --- app/model/entity/AsyncJob.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/model/entity/AsyncJob.php b/app/model/entity/AsyncJob.php index ec29d4319..c86743773 100644 --- a/app/model/entity/AsyncJob.php +++ b/app/model/entity/AsyncJob.php @@ -211,9 +211,21 @@ public function getError(): ?string return $this->error; } + /** + * Makes sure the error string fits the data column. + * Truncates and adds ellipsis '...' at the end if it overflows. + */ + private function sanitizeErrorLength(): void + { + if ($this->error !== null && strlen($this->error) > 250) { + $this->error = substr($this->error, 0, 250) . '...'; + } + } + public function setError(?string $error) { $this->error = $error; + $this->sanitizeErrorLength(); } public function appendError(string $error) @@ -223,6 +235,7 @@ public function appendError(string $error) } else { $this->error .= "\n$error"; } + $this->sanitizeErrorLength(); } /**