Skip to content

Commit 2e511e3

Browse files
Catch storage not available in versions expire command
External storage with session credentials is not accessible without a user session, hence background jobs and CLI commands can't work with them. The previously unhandled exception causes logged errors in the nextcloud log. This patch catches the specific exception and logs it as warnings. So for a production instance the error won't spam their logs for this non-recoverable and technically unsolvable error if the minimum log level is set to the default of 3 (error). Signed-off-by: Christoph Wurst <[email protected]>
1 parent 48ef514 commit 2e511e3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

apps/files_versions/lib/Command/Expire.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
use OC\Command\FileAccess;
2929
use OCA\Files_Versions\Storage;
3030
use OCP\Command\ICommand;
31+
use OCP\Files\StorageNotAvailableException;
32+
use OCP\ILogger;
3133

3234
class Expire implements ICommand {
3335
use FileAccess;
@@ -59,6 +61,20 @@ public function handle() {
5961
return;
6062
}
6163

62-
Storage::expire($this->fileName, $this->user);
64+
try {
65+
Storage::expire($this->fileName, $this->user);
66+
} catch (StorageNotAvailableException $e) {
67+
// In case of external storage and session credentials, the expiration
68+
// fails because the command does not have those credentials
69+
70+
/** @var ILogger $logger */
71+
$logger = \OC::$server->query(ILogger::class);
72+
73+
$logger->logException($e, [
74+
'level' => ILogger::WARN,
75+
'uid' => $this->user,
76+
'fileName' => $this->fileName,
77+
]);
78+
}
6379
}
6480
}

0 commit comments

Comments
 (0)