Skip to content
Merged
Changes from all commits
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
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]>
  • Loading branch information
ChristophWurst committed Nov 25, 2020
commit 2e511e3ea0891ea0d162c9b612fa3150e2cc4403
18 changes: 17 additions & 1 deletion apps/files_versions/lib/Command/Expire.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
use OC\Command\FileAccess;
use OCA\Files_Versions\Storage;
use OCP\Command\ICommand;
use OCP\Files\StorageNotAvailableException;
use OCP\ILogger;

class Expire implements ICommand {
use FileAccess;
Expand Down Expand Up @@ -59,6 +61,20 @@ public function handle() {
return;
}

Storage::expire($this->fileName, $this->user);
try {
Storage::expire($this->fileName, $this->user);
} catch (StorageNotAvailableException $e) {
// In case of external storage and session credentials, the expiration
// fails because the command does not have those credentials

/** @var ILogger $logger */
$logger = \OC::$server->query(ILogger::class);

$logger->logException($e, [
'level' => ILogger::WARN,
'uid' => $this->user,
'fileName' => $this->fileName,
]);
}
}
}