Repository navigation
fix(desktop): classify out-of-space update failures by free disk, not message text #6448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
0263a1b
fix(desktop): classify out-of-space update failures by free disk, not…
saddlepaddle 8624121
fix(desktop): stop the free-space check muting our own updater defects
saddlepaddle a81fa98
fix(desktop): cover the remaining electron-updater defect messages
saddlepaddle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
apps/desktop/src/main/lib/update-error-classification.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { isEnvironmentUpdateError } from "./update-error-classification"; | ||
|
|
||
| const GIGABYTE = 1024 * 1024 * 1024; | ||
| const FULL_VOLUME = 40 * 1024 * 1024; | ||
| const ROOMY_VOLUME = 60 * GIGABYTE; | ||
|
|
||
| // Captured from production, with the account name and archive digest replaced. | ||
| const DITTO_NO_SPACE_EN = [ | ||
| "ditto: /Users/<user>/Library/Caches/com.superset.desktop.ShipIt/update.aBcDeF1/Superset.app/Contents/Resources/app.asar: No space left on device", | ||
| "ditto: Couldn't read pkzip signature.", | ||
| ].join("\n"); | ||
| const SQUIRREL_NO_SPACE_ES = | ||
| "El archivo “<digest>.zip” no puede guardarse porque no queda suficiente espacio.: No hay suficiente espacio. Elimina algunos archivos del volumen e inténtalo de nuevo."; | ||
|
|
||
| const CHECKSUM_MISMATCH = | ||
| "sha512 checksum mismatch, expected 1PbOs3lC, got fT2wPk9d"; | ||
| const SIGNATURE_FAILURE = | ||
| 'Could not get code signature for running application: Error: Command failed: codesign --verify -vvvv "/Applications/Superset.app"'; | ||
| const FEED_FAILURE = | ||
| "HttpError: 404 Not Found\nCannot parse update info from latest-mac.yml"; | ||
| // Further electron-updater release-artifact defects. Each must survive a full | ||
| // volume; a gap here silences a bad release for the users least able to cope. | ||
| const MISSING_CHANNEL = "Cannot find channel “latest-mac.yml” update info"; | ||
| const NO_FILES = "No files provided in update info"; | ||
| const NO_CHECKSUM = | ||
| "Update info doesn't contain nor sha256 neither sha512 checksum"; | ||
|
|
||
| describe("isEnvironmentUpdateError", () => { | ||
| test("classifies a full staging volume without reading the message", () => { | ||
| expect(isEnvironmentUpdateError(DITTO_NO_SPACE_EN, FULL_VOLUME)).toBe(true); | ||
| expect(isEnvironmentUpdateError(SQUIRREL_NO_SPACE_ES, FULL_VOLUME)).toBe( | ||
| true, | ||
| ); | ||
| }); | ||
|
|
||
| test("reports those same failures when the volume has room", () => { | ||
| expect(isEnvironmentUpdateError(DITTO_NO_SPACE_EN, ROOMY_VOLUME)).toBe( | ||
| false, | ||
| ); | ||
| expect(isEnvironmentUpdateError(SQUIRREL_NO_SPACE_ES, ROOMY_VOLUME)).toBe( | ||
| false, | ||
| ); | ||
| }); | ||
|
|
||
| test("reports genuine updater bugs", () => { | ||
| for (const message of [ | ||
| CHECKSUM_MISMATCH, | ||
| SIGNATURE_FAILURE, | ||
| FEED_FAILURE, | ||
| ]) { | ||
| expect(isEnvironmentUpdateError(message, ROOMY_VOLUME)).toBe(false); | ||
| expect(isEnvironmentUpdateError(message, null)).toBe(false); | ||
| } | ||
| }); | ||
|
|
||
| test("still reports our own defects even while the volume is full", () => { | ||
| // A full disk does not corrupt a download or break a signature. If these | ||
| // were suppressed, a bad release would go unreported for exactly the | ||
| // users least able to recover from it. | ||
| for (const message of [ | ||
| CHECKSUM_MISMATCH, | ||
| SIGNATURE_FAILURE, | ||
| FEED_FAILURE, | ||
| MISSING_CHANNEL, | ||
| NO_FILES, | ||
| NO_CHECKSUM, | ||
| ]) { | ||
| expect(isEnvironmentUpdateError(message, FULL_VOLUME)).toBe(false); | ||
| expect(isEnvironmentUpdateError(message, ROOMY_VOLUME)).toBe(false); | ||
| } | ||
| }); | ||
|
|
||
| test("still treats an unrecognised failure on a full volume as environmental", () => { | ||
| expect( | ||
| isEnvironmentUpdateError("something we have never seen", FULL_VOLUME), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("keeps the existing errno and read-only classifications", () => { | ||
| expect( | ||
| isEnvironmentUpdateError( | ||
| "ENOENT: no such file or directory, rename '/Users/<user>/Library/Caches/superset-updater/pending/x.zip'", | ||
| ROOMY_VOLUME, | ||
| ), | ||
| ).toBe(true); | ||
| expect( | ||
| isEnvironmentUpdateError( | ||
| "Error: Cannot update while running on a read-only volume", | ||
| ROOMY_VOLUME, | ||
| ), | ||
| ).toBe(true); | ||
| expect( | ||
| isEnvironmentUpdateError( | ||
| "ENOENT: no such file or directory", | ||
| ROOMY_VOLUME, | ||
| ), | ||
| ).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| const ENVIRONMENT_ERRNO_CODES = [ | ||
| "ENOENT", | ||
| "EACCES", | ||
| "EPERM", | ||
| "EBUSY", | ||
| "ENOSPC", | ||
| ]; | ||
| const UPDATER_PATH_MARKERS = ["-updater", "shipit"]; | ||
|
|
||
| // Staging an update downloads a ~600MB archive into the user's cache directory | ||
| // and unpacks it alongside itself, so a volume with less than this free cannot | ||
| // hold one however we behave. | ||
| export const UPDATE_STAGING_MIN_FREE_BYTES = 1024 * 1024 * 1024; | ||
|
|
||
| // Failures that are ours no matter what the disk looks like: we served a bad | ||
| // artifact, signed it wrong, or published an unreadable feed. A full volume | ||
| // does not cause any of these, so they must be checked before the free-space | ||
| // heuristic — otherwise a genuine release defect goes unreported for every | ||
| // user who happens to be low on space. | ||
| // Keep this list ahead of the release-artifact failure modes electron-updater | ||
| // can surface. A missing entry means that defect is silently suppressed for | ||
| // every user low on disk, which is the failure this ordering exists to prevent. | ||
| const UPDATER_DEFECT_PATTERNS = [ | ||
| "checksum", // mismatch, and "doesn't contain nor sha256 neither sha512 checksum" | ||
| "code signature", | ||
| "codesign", | ||
| "cannot parse update info", | ||
| "cannot find channel", | ||
| "no files provided", | ||
| ]; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| // Update failures owned by the user's machine, not by us. A full volume is the | ||
| // common one, and neither staging tool gives us a code to match: `ditto` prints | ||
| // an errno-free line and Squirrel forwards NSError text localised to the user's | ||
| // language, so ask the filesystem how much room is left rather than reading the | ||
| // words. The rest — a corrupt or half-removed updater cache, an app bundle that | ||
| // can't be written, stalled requests — arrive as plain messages without errno | ||
| // properties, so those still match on the text. | ||
| export function isEnvironmentUpdateError( | ||
| message: string, | ||
| freeStagingBytes: number | null, | ||
| ): boolean { | ||
| const lowerMessage = message.toLowerCase(); | ||
| if ( | ||
| UPDATER_DEFECT_PATTERNS.some((pattern) => lowerMessage.includes(pattern)) | ||
| ) { | ||
| return false; | ||
| } | ||
| if ( | ||
| freeStagingBytes !== null && | ||
| freeStagingBytes < UPDATE_STAGING_MIN_FREE_BYTES | ||
| ) { | ||
| return true; | ||
| } | ||
| if ( | ||
| lowerMessage.includes("read-only volume") || | ||
| lowerMessage.includes("the request timed out") | ||
| ) { | ||
| return true; | ||
| } | ||
| return ( | ||
| ENVIRONMENT_ERRNO_CODES.some((code) => message.includes(`${code}:`)) && | ||
| UPDATER_PATH_MARKERS.some((marker) => lowerMessage.includes(marker)) | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 1248
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 50376
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 30244
🌐 Web query:
Electron app.getPath("cache") macOS path documentation and whether it shares ~/Library/Caches with electron-updater baseCachePath💡 Result:
On macOS, the Electron
app.getPath("cache")method returns the standard per-user application cache directory, which defaults to~/Library/Caches[1]. Regardingelectron-updater, it does not share the same base directory asapp.getPath("cache")[2][3]. Whileapp.getPath("cache")points to~/Library/Caches, theelectron-updaterbaseCachePath(on macOS) defaults to~/Library/Application Support/Caches[2][3]. In summary: * Electron'sapp.getPath("cache"): Resolves to~/Library/Caches[1]. *electron-updaterbase cache: Resolves to~/Library/Application Support/Caches[2][3]. Because these paths are distinct locations in the macOS file system, they are not shared [2][3]. The updater creates a specific sub-directory within its own base path (typically named{appName}-updater) to store downloaded update files [2][4][5].Citations:
baseCachePathfor updater download location electron-userland/electron-builder#8719🌐 Web query:
site:electronjs.org/docs/latest/api/app app.getPath cache macOS default path💡 Result:
The Electron API does not include a 'cache' name for the app.getPath(name) method [1]. In Electron, application caches, such as cookies, local storage, disk caches, and network state, are stored in the directory defined by the sessionData path [1]. By default, the sessionData path points to the userData directory [1]. The userData directory is the standard location for an app's configuration files, and it is typically located within the user's application support directory on macOS [1]. Because Chromium may write very large files to the sessionData directory, it is recommended to override this path if your application does not rely on browser storage, in order to avoid polluting the userData folder [1]. You can override the path using app.setPath before the ready event of the app module is emitted [1].
Citations:
🌐 Web query:
electron-updater 6.8.3 getAppCacheDir baseCachePath macOS source💡 Result:
In electron-updater version 6.8.3, the function getAppCacheDir is defined in the AppAdapter module [1][2]. It serves as a base directory provider and, specifically on macOS (darwin), it returns the path to the user's Caches directory: ~/Library/Caches [2]. It is important to note that getAppCacheDir returns the parent directory, not the final application-specific cache folder [3]. The complete cache path used by the updater is constructed by joining this base path with an application-specific updaterCacheDirName (typically the sanitized application name followed by -updater) [4][5][6]. On macOS, the full path is: ~/Library/Caches/{sanitized-app-name}-updater [4][5] Historical context indicates that in older versions, this was incorrectly located in ~/Library/Application Support/Caches, but it was moved to the standard ~/Library/Caches to align with proper macOS conventions [7]. The baseCachePath property in the AppAdapter interface reflects this base cache directory [1][8][2].
Citations:
baseCachePathfor updater download location electron-userland/electron-builder#8719electron-updatercache directory on macOS electron-userland/electron-builder#7032🏁 Script executed:
Repository: superset-sh/superset
Length of output: 5886
Measure the updater cache volume instead of
userData.electron-updater@6.8.3uses an OS cache root and appends its updater directory. Electron’sapp.getPath()has no"cache"key. Resolve the same updater cache path before callingstatfsSync; otherwise Sentry classification can use the wrong volume.🤖 Prompt for AI Agents