Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,18 @@ async function checkForUpdates(silent = false) {
}
return;
}
await autoUpdater.checkForUpdates();
// Update-check failures (404 when the release manifest isn't published yet,
// offline, rate-limited) are surfaced to the user via the autoUpdater "error"
// event handler. The promise returned by checkForUpdates() ALSO rejects on
// those, so it must be caught here — the startup check (line ~928) fires it
// unawaited inside a setTimeout, and an uncaught rejection there becomes an
// "Unhandled Rejection" that the packaged-app smoke test treats as fatal.
try {
await autoUpdater.checkForUpdates();
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
console.warn("[Electron] Update check failed (non-fatal):", msg);
}
}

async function downloadUpdate() {
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/electron-main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,36 @@
}
});

// ─── Auto-updater unhandled-rejection guard (v3.8.13) ────────
//
// checkForUpdates() is fired unawaited from a setTimeout at startup. The
// underlying autoUpdater.checkForUpdates() rejects on a 404 (no published
// update manifest yet), offline, or rate-limit — and an uncaught rejection
// there surfaces as an "Unhandled Rejection" that the packaged-app smoke test
// treats as fatal (it failed the macOS-intel build for v3.8.13). The call must
// be wrapped so the rejection never escapes.

describe("Electron auto-updater rejection handling (v3.8.13)", () => {
const mainSrc = readFileSync(join(import.meta.dirname, "../../electron/main.js"), "utf8");

it("wraps autoUpdater.checkForUpdates() so a 404/offline check can't become an unhandled rejection", () => {
const fn = mainSrc.match(/async function checkForUpdates\([\s\S]*?\n}/);
assert.ok(fn, "checkForUpdates function should exist in electron/main.js");
const body = fn![0];
assert.match(body, /try\s*\{/, "checkForUpdates must wrap the update check in try/catch");
assert.match(
body,
/catch\s*\([\s\S]*?\)\s*\{/,
"checkForUpdates must catch the rejecting autoUpdater.checkForUpdates() call"
);
assert.match(
body,
/try[\s\S]*await autoUpdater\.checkForUpdates\(\)[\s\S]*catch/,
"autoUpdater.checkForUpdates() must sit inside the try block"
);
});
});

// ─── URL Validation Tests ────────────────────────────────────

describe("Electron URL Validation", () => {
Expand Down Expand Up @@ -216,7 +246,7 @@
describe("Server Port Management", () => {
it("should have valid default port", () => {
const DEFAULT_PORT = 20128;
assert.ok(DEFAULT_PORT > 0 && DEFAULT_PORT <= 65535);

Check warning on line 249 in tests/unit/electron-main.test.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this assertion; it always succeeds or fails.

See more on https://sonarcloud.io/project/issues?id=diegosouzapw_OmniRoute&issues=AZ6fnMiRWneQtRL6NFnO&open=AZ6fnMiRWneQtRL6NFnO&pullRequest=3339
});

it("should validate port numbers", () => {
Expand Down