fix: fail gracefully when remote XML data cannot be read during sync

This commit is contained in:
Björn Fromme
2025-12-22 08:29:57 +01:00
parent c9426eff3b
commit 9291adfdff
2 changed files with 18 additions and 11 deletions
+16 -9
View File
@@ -63,13 +63,12 @@ class BpnXmlSyncCommand extends Command
$force = $input->getOption('force');
$dryRun = $input->getOption('dry-run');
try {
$remoteInfo = $this->readRemoteInfo();
} catch (FilesystemException|\InvalidArgumentException $e) {
$io->error(sprintf('Failed to read remote info: %s', $e->getMessage()));
$this->logger->error('XML sync failed: could not read remote info', ['exception' => $e]);
$remoteInfo = $this->readRemoteInfo();
return Command::FAILURE;
if (null === $remoteInfo) {
$io->warning('Remote info unavailable - will retry on next scheduled run');
return Command::SUCCESS;
}
$io->text(sprintf(
@@ -127,11 +126,19 @@ class BpnXmlSyncCommand extends Command
return Command::SUCCESS;
}
private function readRemoteInfo(): XmlExportInfo
private function readRemoteInfo(): ?XmlExportInfo
{
$content = $this->xmlSource->read(XmlExportInfo::getFilename());
try {
$content = $this->xmlSource->read(XmlExportInfo::getFilename());
return XmlExportInfo::fromString($content);
return XmlExportInfo::fromString($content);
} catch (FilesystemException|\InvalidArgumentException $e) {
$this->logger->warning('Could not read remote info file, likely being updated', [
'exception' => $e->getMessage(),
]);
return null;
}
}
private function readLocalInfo(): ?XmlExportInfo