Skip to content

Commit aef3ac6

Browse files
miaulalalabackportbot[bot]
authored andcommitted
fix(appstore): address review comments on GenericFileException handling
- Attempt delete before logging the warning, so the warning only fires when we know recovery will succeed - Log an error (not silently return) when delete itself fails - Use catch (\Exception) without variable (PHP 8) - Replace willReturnArgument(1) with explicit willReturn(true) in test - Add blank lines between logical blocks in test for readability Signed-off-by: Anna Larch <anna@nextcloud.com> AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 583e0b2 commit aef3ac6

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

lib/private/App/AppStore/Fetcher/Fetcher.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,13 @@ public function get($allowUnstable = false) {
165165
// File does not already exist
166166
$file = $rootFolder->newFile($this->fileName);
167167
} catch (GenericFileException $e) {
168-
$this->logger->warning('Could not read appstore cache file, it will be refreshed', ['app' => 'appstoreFetcher', 'exception' => $e]);
169168
try {
170169
$file->delete();
171-
} catch (\Exception $deleteException) {
170+
} catch (\Exception) {
171+
$this->logger->error('Could not read appstore cache file', ['app' => 'appstoreFetcher', 'exception' => $e]);
172172
return [];
173173
}
174+
$this->logger->warning('Could not read appstore cache file, it will be refreshed', ['app' => 'appstoreFetcher', 'exception' => $e]);
174175
$file = $rootFolder->newFile($this->fileName);
175176
}
176177

tests/lib/App/AppStore/Fetcher/FetcherBase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ public function testGetWithUnreadableCacheFileRecreatesAndFetches(): void {
697697
return $default;
698698
});
699699
$this->config->method('getSystemValueBool')
700-
->willReturnArgument(1);
700+
->willReturn(true);
701701

702702
$folder = $this->createMock(ISimpleFolder::class);
703703
$corruptedFile = $this->createMock(ISimpleFile::class);
@@ -724,6 +724,7 @@ public function testGetWithUnreadableCacheFileRecreatesAndFetches(): void {
724724
->method('newFile')
725725
->with($this->fileName)
726726
->willReturn($freshFile);
727+
727728
$client = $this->createMock(IClient::class);
728729
$this->clientService
729730
->expects($this->once())
@@ -742,6 +743,7 @@ public function testGetWithUnreadableCacheFileRecreatesAndFetches(): void {
742743
$response->method('getHeader')
743744
->with($this->equalTo('ETag'))
744745
->willReturn('"myETag"');
746+
745747
$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
746748
$freshFile
747749
->expects($this->once())

0 commit comments

Comments
 (0)