From bacb314d7185971a892b4c95dc60ceb4999bdb85 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sat, 5 Dec 2026 23:39:23 +0100 Subject: [PATCH 1/3] refactor(core): type share manager l10n as non-nullable The IL10N instance is always set in the constructor from IFactory::get(), which never returns null. The nullable type only produced 42 psalm baseline entries. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ferdinand Thiessen --- apps/files_sharing/tests/CapabilitiesTest.php | 6 ++- build/psalm-baseline.xml | 42 ------------------- lib/private/Share20/Manager.php | 2 +- 3 files changed, 6 insertions(+), 44 deletions(-) diff --git a/apps/files_sharing/tests/CapabilitiesTest.php b/apps/files_sharing/tests/CapabilitiesTest.php index 712ba36d02158..f57a2b6fc4fbe 100644 --- a/apps/files_sharing/tests/CapabilitiesTest.php +++ b/apps/files_sharing/tests/CapabilitiesTest.php @@ -21,6 +21,7 @@ use OCP\IDateTimeZone; use OCP\IDBConnection; use OCP\IGroupManager; +use OCP\IL10N; use OCP\IUserManager; use OCP\IUserSession; use OCP\L10N\IFactory; @@ -77,6 +78,9 @@ private function getResults(array $map, array $typedMap = [], bool $federationEn }); } + $l10nFactory = $this->createMock(IFactory::class); + $l10nFactory->method('get')->willReturn($this->createMock(IL10N::class)); + $shareManager = new Manager( $this->createMock(LoggerInterface::class), $config, @@ -84,7 +88,7 @@ private function getResults(array $map, array $typedMap = [], bool $federationEn $this->createMock(IHasher::class), $this->createMock(IMountManager::class), $this->createMock(IGroupManager::class), - $this->createMock(IFactory::class), + $l10nFactory, $this->createMock(IProviderFactory::class), $this->createMock(IUserManager::class), $this->createMock(IRootFolder::class), diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 0a1f413cc9243..6dec2fb36c315 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -10648,48 +10648,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 569197a1eaf22..cc391b41dfc4e 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -91,7 +91,7 @@ */ class Manager implements IManager { - private ?IL10N $l; + private IL10N $l; public function __construct( private LoggerInterface $logger, From 1854c6d0a37fc77751b8e1f84bbc32013591b082 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sat, 5 Dec 2026 23:39:49 +0100 Subject: [PATCH 2/3] refactor(core): type updater logger as non-nullable The updater is only built by the DI container, which always injects a logger. The nullable type only produced 31 psalm baseline entries. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ferdinand Thiessen --- build/psalm-baseline.xml | 33 --------------------------------- lib/private/Updater.php | 2 +- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 6dec2fb36c315..8885947bdc682 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -10958,39 +10958,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/lib/private/Updater.php b/lib/private/Updater.php index 5337f52b5e305..724d39c6d76c3 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -60,7 +60,7 @@ public function __construct( private IConfig $config, private IAppConfig $appConfig, private Checker $checker, - private ?LoggerInterface $log, + private LoggerInterface $log, private Installer $installer, private IAppManager $appManager, ) { From d7fdb815bfda5045b3825005a979073b331de922 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sat, 5 Dec 2026 23:41:29 +0100 Subject: [PATCH 3/3] fix(files): cast failed storage exception code to int Exception codes are not always integers: PDOException carries the SQLSTATE string (e.g. "HY000"). Passing such a code on to StorageNotAvailableException threw a TypeError, so callers never got the StorageNotAvailableException they handle. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ferdinand Thiessen --- build/psalm-baseline.xml | 42 ---------- lib/private/Files/Storage/FailedStorage.php | 80 ++++++++++--------- tests/lib/Files/Storage/FailedStorageTest.php | 44 ++++++++++ 3 files changed, 86 insertions(+), 80 deletions(-) create mode 100644 tests/lib/Files/Storage/FailedStorageTest.php diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 8885947bdc682..22cd313e89b6e 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -8931,48 +8931,6 @@ getBody()]]> - - - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - e->getCode()]]> - - diff --git a/lib/private/Files/Storage/FailedStorage.php b/lib/private/Files/Storage/FailedStorage.php index e6e3b8f8f4c88..68db5035576d2 100644 --- a/lib/private/Files/Storage/FailedStorage.php +++ b/lib/private/Files/Storage/FailedStorage.php @@ -38,157 +38,157 @@ public function getId(): string { #[\Override] public function mkdir(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function rmdir(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function opendir(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function is_dir(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function is_file(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function stat(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function filetype(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function filesize(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function isCreatable(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function isReadable(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function isUpdatable(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function isDeletable(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function isSharable(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function getPermissions(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function file_exists(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function filemtime(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function file_get_contents(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function file_put_contents(string $path, mixed $data): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function unlink(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function rename(string $source, string $target): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function copy(string $source, string $target): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function fopen(string $path, string $mode): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function getMimeType(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function hash(string $type, string $path, bool $raw = false): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function free_space(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function touch(string $path, ?int $mtime = null): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function getLocalFile(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function hasUpdated(string $path, int $time): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function getETag(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function getDirectDownload(string $path): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function getDirectDownloadById(string $fileId): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] @@ -197,37 +197,41 @@ public function verifyPath(string $path, string $fileName): void { #[\Override] public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, bool $preserveMtime = false): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function acquireLock(string $path, int $type, ILockingProvider $provider): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function releaseLock(string $path, int $type, ILockingProvider $provider): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function changeLock(string $path, int $type, ILockingProvider $provider): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function getAvailability(): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); } #[\Override] public function setAvailability(bool $isAvailable): never { - throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); + $this->throwUnavailable(); + } + + private function throwUnavailable(): never { + throw new StorageNotAvailableException($this->e->getMessage(), (int)$this->e->getCode(), $this->e); } #[\Override] diff --git a/tests/lib/Files/Storage/FailedStorageTest.php b/tests/lib/Files/Storage/FailedStorageTest.php new file mode 100644 index 0000000000000..f99f0302e8a63 --- /dev/null +++ b/tests/lib/Files/Storage/FailedStorageTest.php @@ -0,0 +1,44 @@ + $original]); + + try { + $storage->file_get_contents('foo.txt'); + $this->fail('Expected StorageNotAvailableException'); + } catch (StorageNotAvailableException $e) { + $this->assertSame('backend is down', $e->getMessage()); + $this->assertSame(42, $e->getCode()); + $this->assertSame($original, $e->getPrevious()); + } + } + + public function testThrowsStorageNotAvailableForStringExceptionCode(): void { + $original = new \PDOException('connection refused'); + (new \ReflectionProperty(\Exception::class, 'code'))->setValue($original, 'HY000'); + $storage = new FailedStorage(['exception' => $original]); + + try { + $storage->mkdir('foo'); + $this->fail('Expected StorageNotAvailableException'); + } catch (StorageNotAvailableException $e) { + $this->assertSame('connection refused', $e->getMessage()); + $this->assertSame($original, $e->getPrevious()); + } + } +}