mirror of
https://github.com/readest/readest.git
synced 2026-07-09 16:00:16 +00:00
fix(updater): never throw from an auto update check (#5028)
checkForAppUpdates runs fire-and-forget on reader/library mount, but it threw on any network failure: the desktop check() propagated "error sending request for url (...latest.json)" (READEST-J) and the Android branch re-threw "Failed to fetch Android update info" (READEST-22). Both surfaced as unhandled rejections. Wrap the check so a failure is swallowed (returns false) for an auto-check; manual checks (About window) still surface the error. Adds regression tests. Fixes READEST-J Fixes READEST-22 Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
fdd13a5a6a
commit
15cca23773
2 changed files with 71 additions and 39 deletions
|
|
@ -256,6 +256,24 @@ describe('updater', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('auto-check swallows Android update failure (READEST-22)', async () => {
|
||||
mockOsType.mockReturnValue('android');
|
||||
mockTauriFetch.mockRejectedValue(new Error('Network error'));
|
||||
|
||||
// Auto-check runs fire-and-forget on mount; a network failure must resolve
|
||||
// false, not reject (which would become an unhandled rejection).
|
||||
await expect(checkForAppUpdates(dummyTranslate, true)).resolves.toBe(false);
|
||||
});
|
||||
|
||||
test('auto-check swallows desktop update failure (READEST-J)', async () => {
|
||||
mockOsType.mockReturnValue('macos');
|
||||
mockCheck.mockRejectedValue(
|
||||
new Error('error sending request for url (releases/latest/download/latest.json)'),
|
||||
);
|
||||
|
||||
await expect(checkForAppUpdates(dummyTranslate, true)).resolves.toBe(false);
|
||||
});
|
||||
|
||||
test('returns false for unsupported OS types', async () => {
|
||||
mockOsType.mockReturnValue('ios');
|
||||
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ export const checkForAppUpdates = async (
|
|||
console.log('Checking for updates', { updateChannel });
|
||||
const OS_TYPE = osType();
|
||||
|
||||
try {
|
||||
if (updateChannel === 'nightly') {
|
||||
const platformKey = getNightlyPlatformKey(
|
||||
OS_TYPE,
|
||||
|
|
@ -180,7 +181,10 @@ export const checkForAppUpdates = async (
|
|||
const response = await fetch(READEST_UPDATER_FILE, { connectTimeout: 5000 });
|
||||
const data = await response.json();
|
||||
const isNewer = semver.gt(data.version, getAppVersion());
|
||||
if (isNewer && ('android-arm64' in data.platforms || 'android-universal' in data.platforms)) {
|
||||
if (
|
||||
isNewer &&
|
||||
('android-arm64' in data.platforms || 'android-universal' in data.platforms)
|
||||
) {
|
||||
setUpdaterWindowVisible(true, data.version!, getAppVersion());
|
||||
}
|
||||
return isNewer;
|
||||
|
|
@ -191,6 +195,16 @@ export const checkForAppUpdates = async (
|
|||
}
|
||||
|
||||
return false;
|
||||
} catch (err) {
|
||||
// Update checks are best-effort: they fail routinely when offline or when
|
||||
// the release host is unreachable. An auto-check runs fire-and-forget on
|
||||
// mount, so throwing here becomes an unhandled rejection (READEST-J desktop
|
||||
// latest.json, READEST-22 Android update info). Only surface the failure for
|
||||
// a manual check (About window).
|
||||
console.warn('Update check failed', err);
|
||||
if (!isAutoCheck) throw err;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const LAST_SHOWN_RELEASE_NOTES_KEY = 'lastShownReleaseNotesVersion';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue