From 714e495a7cba63154847f05b56f914f7a0f63473 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Fri, 26 Jul 2024 13:22:41 +0200 Subject: [PATCH] fix(TaskProcessing): Catch JSON encode errors in Manager#setTaskResult Signed-off-by: Marcel Klehr --- lib/private/TaskProcessing/Manager.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php index cb1e4e1e04136..e7d10b0a01e4a 100644 --- a/lib/private/TaskProcessing/Manager.php +++ b/lib/private/TaskProcessing/Manager.php @@ -863,9 +863,9 @@ public function setTaskResult(int $id, ?string $error, ?array $result, bool $isU $task->setProgress(1); $task->setStatus(Task::STATUS_FAILED); $task->setEndedAt(time()); - $error = 'The task was processed successfully but the provider\'s output doesn\'t pass validation against the task type\'s outputShape spec and/or the provider\'s own optionalOutputShape spec'; + $error = 'The task was processed successfully but the provider\'s output doesn\'t pass validation against the task type\'s outputShape spec and/or the provider\'s own optionalOutputShape spec.'; $task->setErrorMessage($error); - $this->logger->error($error, ['exception' => $e]); + $this->logger->error($error . ' Output was: ' . var_export($result, true), ['exception' => $e]); } catch (NotPermittedException $e) { $task->setProgress(1); $task->setStatus(Task::STATUS_FAILED); @@ -882,7 +882,11 @@ public function setTaskResult(int $id, ?string $error, ?array $result, bool $isU $this->logger->error($error, ['exception' => $e]); } } - $taskEntity = \OC\TaskProcessing\Db\Task::fromPublicTask($task); + try { + $taskEntity = \OC\TaskProcessing\Db\Task::fromPublicTask($task); + } catch (\JsonException $e) { + throw new \OCP\TaskProcessing\Exception\Exception('The task was processed successfully but the provider\'s output could not be encoded as JSON for the database.', 0, $e); + } try { $this->taskMapper->update($taskEntity); $this->runWebhook($task);