Skip to content

Commit ee2329a

Browse files
committed
fix(TaskProcessing): increase error_message column length
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
1 parent 14dfa3b commit ee2329a

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OC\Core\Migrations;
11+
12+
use Closure;
13+
use OCP\DB\ISchemaWrapper;
14+
use OCP\Migration\Attributes\ModifyColumn;
15+
use OCP\Migration\IOutput;
16+
use OCP\Migration\SimpleMigrationStep;
17+
18+
#[ModifyColumn(table: 'taskprocessing_tasks', name: 'error_message', description: 'Increase column length to 2048 bytes to support longer error messages')]
19+
class Version30000Date20240906095113 extends SimpleMigrationStep {
20+
21+
/**
22+
* @param IOutput $output
23+
* @param Closure(): ISchemaWrapper $schemaClosure
24+
* @param array $options
25+
* @return null|ISchemaWrapper
26+
*/
27+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
28+
/** @var ISchemaWrapper $schema */
29+
$schema = $schemaClosure();
30+
31+
$table = $schema->getTable('taskprocessing_tasks');
32+
$column = $table->getColumn('error_message');
33+
34+
if ($column->getLength() < 2048) {
35+
$column->setLength(2048);
36+
}
37+
38+
return $schema;
39+
}
40+
}

lib/private/TaskProcessing/Manager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,8 @@ public function setTaskResult(int $id, ?string $error, ?array $result, bool $isU
830830
if ($error !== null) {
831831
$task->setStatus(Task::STATUS_FAILED);
832832
$task->setEndedAt(time());
833-
$task->setErrorMessage($error);
833+
// truncate error message to 2048 bytes
834+
$task->setErrorMessage(substr($error, 0, 2048));
834835
$this->logger->warning('A TaskProcessing ' . $task->getTaskTypeId() . ' task with id ' . $id . ' failed with the following message: ' . $error);
835836
} elseif ($result !== null) {
836837
$taskTypes = $this->getAvailableTaskTypes();
@@ -895,7 +896,7 @@ public function setTaskResult(int $id, ?string $error, ?array $result, bool $isU
895896
$this->taskMapper->update($taskEntity);
896897
$this->runWebhook($task);
897898
} catch (\OCP\DB\Exception $e) {
898-
throw new \OCP\TaskProcessing\Exception\Exception('There was a problem finding the task', 0, $e);
899+
throw new \OCP\TaskProcessing\Exception\Exception($e->getMessage());
899900
}
900901
if ($task->getStatus() === Task::STATUS_SUCCESSFUL) {
901902
$event = new TaskSuccessfulEvent($task);

0 commit comments

Comments
 (0)