Skip to content

Commit b06d294

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 5d9dd80 commit b06d294

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
@@ -704,7 +704,7 @@ public function testGetWithUnreadableCacheFileRecreatesAndFetches(): void {
704704
return $default;
705705
});
706706
$this->config->method('getSystemValueBool')
707-
->willReturnArgument(1);
707+
->willReturn(true);
708708

709709
$folder = $this->createMock(ISimpleFolder::class);
710710
$corruptedFile = $this->createMock(ISimpleFile::class);
@@ -731,6 +731,7 @@ public function testGetWithUnreadableCacheFileRecreatesAndFetches(): void {
731731
->method('newFile')
732732
->with($this->fileName)
733733
->willReturn($freshFile);
734+
734735
$client = $this->createMock(IClient::class);
735736
$this->clientService
736737
->expects($this->once())
@@ -749,6 +750,7 @@ public function testGetWithUnreadableCacheFileRecreatesAndFetches(): void {
749750
$response->method('getHeader')
750751
->with($this->equalTo('ETag'))
751752
->willReturn('"myETag"');
753+
752754
$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
753755
$freshFile
754756
->expects($this->once())

0 commit comments

Comments
 (0)