From d11b9cbd7993042fcf9ba49d5c8ef14bf928d901 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Mon, 6 Nov 2023 12:50:16 +0100 Subject: [PATCH] fix(TextProcessing/Manager): Throw TaskFailureException upon failure Signed-off-by: Marcel Klehr --- core/Controller/TextProcessingApiController.php | 3 ++- lib/private/TextProcessing/Manager.php | 10 +++------- .../TextProcessing/Exception/TaskFailureException.php | 7 +++++++ lib/public/TextProcessing/IManager.php | 5 +++-- 4 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 lib/public/TextProcessing/Exception/TaskFailureException.php diff --git a/core/Controller/TextProcessingApiController.php b/core/Controller/TextProcessingApiController.php index 6b975a7ed61..a6b85fd46ae 100644 --- a/core/Controller/TextProcessingApiController.php +++ b/core/Controller/TextProcessingApiController.php @@ -38,6 +38,7 @@ use OCP\Common\Exception\NotFoundException; use OCP\DB\Exception; use OCP\IL10N; use OCP\IRequest; +use OCP\TextProcessing\Exception\TaskFailureException; use OCP\TextProcessing\ITaskType; use OCP\TextProcessing\Task; use OCP\TextProcessing\IManager; @@ -121,7 +122,7 @@ class TextProcessingApiController extends \OCP\AppFramework\OCSController { try { try { $this->textProcessingManager->runOrScheduleTask($task); - } catch(\RuntimeException) { + } catch(TaskFailureException) { // noop, because the task object has the failure status set already, we just return the task json } diff --git a/lib/private/TextProcessing/Manager.php b/lib/private/TextProcessing/Manager.php index bee70b53a33..439ffde4521 100644 --- a/lib/private/TextProcessing/Manager.php +++ b/lib/private/TextProcessing/Manager.php @@ -28,6 +28,7 @@ namespace OC\TextProcessing; use OC\AppFramework\Bootstrap\Coordinator; use OC\TextProcessing\Db\Task as DbTask; use OCP\IConfig; +use OCP\TextProcessing\Exception\TaskFailureException; use OCP\TextProcessing\IProvider2; use OCP\TextProcessing\Task; use OCP\TextProcessing\Task as OCPTask; @@ -139,22 +140,17 @@ class Manager implements IManager { $task->setStatus(OCPTask::STATUS_SUCCESSFUL); $this->taskMapper->update(DbTask::fromPublicTask($task)); return $output; - } catch (\RuntimeException $e) { - $this->logger->info('LanguageModel call using provider ' . $provider->getName() . ' failed', ['exception' => $e]); - $task->setStatus(OCPTask::STATUS_FAILED); - $this->taskMapper->update(DbTask::fromPublicTask($task)); - throw $e; } catch (\Throwable $e) { $this->logger->info('LanguageModel call using provider ' . $provider->getName() . ' failed', ['exception' => $e]); $task->setStatus(OCPTask::STATUS_FAILED); $this->taskMapper->update(DbTask::fromPublicTask($task)); - throw new RuntimeException('LanguageModel call using provider ' . $provider->getName() . ' failed: ' . $e->getMessage(), 0, $e); + throw new TaskFailureException('LanguageModel call using provider ' . $provider->getName() . ' failed: ' . $e->getMessage(), 0, $e); } } $task->setStatus(OCPTask::STATUS_FAILED); $this->taskMapper->update(DbTask::fromPublicTask($task)); - throw new RuntimeException('Could not run task'); + throw new TaskFailureException('Could not run task'); } /** diff --git a/lib/public/TextProcessing/Exception/TaskFailureException.php b/lib/public/TextProcessing/Exception/TaskFailureException.php new file mode 100644 index 00000000000..5f7b308757b --- /dev/null +++ b/lib/public/TextProcessing/Exception/TaskFailureException.php @@ -0,0 +1,7 @@ +