Skip to content

Commit

Permalink
fix(TaskProcessing): increase error_message column length
Browse files Browse the repository at this point in the history
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
  • Loading branch information
kyteinsky committed Sep 6, 2024
1 parent 14dfa3b commit ee2329a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
40 changes: 40 additions & 0 deletions core/Migrations/Version30000Date20240906095113.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC\Core\Migrations;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\Attributes\ModifyColumn;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

#[ModifyColumn(table: 'taskprocessing_tasks', name: 'error_message', description: 'Increase column length to 2048 bytes to support longer error messages')]
class Version30000Date20240906095113 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$table = $schema->getTable('taskprocessing_tasks');
$column = $table->getColumn('error_message');

if ($column->getLength() < 2048) {
$column->setLength(2048);
}

return $schema;
}
}
5 changes: 3 additions & 2 deletions lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,8 @@ public function setTaskResult(int $id, ?string $error, ?array $result, bool $isU
if ($error !== null) {
$task->setStatus(Task::STATUS_FAILED);
$task->setEndedAt(time());
$task->setErrorMessage($error);
// truncate error message to 2048 bytes
$task->setErrorMessage(substr($error, 0, 2048));
$this->logger->warning('A TaskProcessing ' . $task->getTaskTypeId() . ' task with id ' . $id . ' failed with the following message: ' . $error);
} elseif ($result !== null) {
$taskTypes = $this->getAvailableTaskTypes();
Expand Down Expand Up @@ -895,7 +896,7 @@ public function setTaskResult(int $id, ?string $error, ?array $result, bool $isU
$this->taskMapper->update($taskEntity);
$this->runWebhook($task);
} catch (\OCP\DB\Exception $e) {
throw new \OCP\TaskProcessing\Exception\Exception('There was a problem finding the task', 0, $e);
throw new \OCP\TaskProcessing\Exception\Exception($e->getMessage());
}
if ($task->getStatus() === Task::STATUS_SUCCESSFUL) {
$event = new TaskSuccessfulEvent($task);
Expand Down

0 comments on commit ee2329a

Please sign in to comment.