Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(TextProcessing/Manager): Throw TaskFailureException upon failure
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Nov 6, 2023
commit d11b9cbd7993042fcf9ba49d5c8ef14bf928d901
3 changes: 2 additions & 1 deletion core/Controller/TextProcessingApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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;
Expand Down Expand Up @@ -121,7 +122,7 @@ public function schedule(string $input, string $type, string $appId, string $ide
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
}

Expand Down
10 changes: 3 additions & 7 deletions lib/private/TextProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -139,22 +140,17 @@ public function runTask(OCPTask $task): string {
$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');
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace OCP\TextProcessing\Exception;

class TaskFailureException extends \RuntimeException {

}
5 changes: 3 additions & 2 deletions lib/public/TextProcessing/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\Common\Exception\NotFoundException;
use OCP\DB\Exception;
use OCP\PreConditionNotMetException;
use OCP\TextProcessing\Exception\TaskFailureException;
use RuntimeException;

/**
Expand Down Expand Up @@ -57,7 +58,7 @@ public function getAvailableTaskTypes(): array;
/**
* @param Task $task The task to run
* @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
* @throws RuntimeException If something else failed
* @throws TaskFailureException If running the task failed
* @since 27.1.0
*/
public function runTask(Task $task): string;
Expand All @@ -82,7 +83,7 @@ public function scheduleTask(Task $task) : void;
* @param Task $task The task to schedule
* @returns bool A boolean indicating whether the task was run synchronously (`true`) or offloaded to a background job (`false`)
* @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
* @throws RuntimeException If running the task failed
* @throws TaskFailureException If running the task failed
* @throws Exception storing the task in the database failed
* @since 28.0.0
*/
Expand Down