-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(editor): show an error instead of an endless skeleton when metadata fails #2044
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
Open
DPS0340
wants to merge
1
commit into
CapSoftware:main
Choose a base branch
from
DPS0340:fix/editor-meta-load-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+117
−18
Open
Changes from all commits
Commits
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
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,54 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { deriveImportStatus, deriveRawImportStatus } from "./import-status"; | ||
|
|
||
| describe("editor import status", () => { | ||
| it("reports loading while the metadata query is still in flight", () => { | ||
| expect(deriveRawImportStatus({ data: undefined, isError: false })).toBe( | ||
| "loading", | ||
| ); | ||
| }); | ||
|
|
||
| it("reports ready once metadata arrives", () => { | ||
| expect( | ||
| deriveRawImportStatus({ data: { status: null }, isError: false }), | ||
| ).toBe("ready"); | ||
| }); | ||
|
|
||
| it("reports importing while an import is in progress", () => { | ||
| expect( | ||
| deriveRawImportStatus({ | ||
| data: { status: { status: "InProgress" } }, | ||
| isError: false, | ||
| }), | ||
| ).toBe("importing"); | ||
| }); | ||
|
|
||
| // #1812: a failed query also has no data. Before the fix this returned | ||
| // "loading", so an unreadable recording-meta.json left the editor on the | ||
| // skeleton with no error and no way forward. | ||
| it("reports error when the metadata query fails", () => { | ||
| expect(deriveRawImportStatus({ data: undefined, isError: true })).toBe( | ||
| "error", | ||
| ); | ||
| }); | ||
|
|
||
| it("still reports error when a stale success payload is present", () => { | ||
| expect( | ||
| deriveRawImportStatus({ data: { status: null }, isError: true }), | ||
| ).toBe("error"); | ||
| }); | ||
|
|
||
| it("keeps showing the import screen while the lock is held", () => { | ||
| expect(deriveImportStatus("loading", true)).toBe("importing"); | ||
| }); | ||
|
|
||
| it("lets an error override the importing lock", () => { | ||
| expect(deriveImportStatus("error", true)).toBe("error"); | ||
| }); | ||
|
|
||
| it("passes through the raw status when nothing is latched", () => { | ||
| expect(deriveImportStatus("ready", false)).toBe("ready"); | ||
| expect(deriveImportStatus("loading", false)).toBe("loading"); | ||
| }); | ||
| }); |
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,48 @@ | ||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Which screen the editor should show while a recording's metadata loads. | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * Extracted from `Editor.tsx` so the state machine can be tested without a | ||||||||||||||||||||
| * running editor. The case that matters is `error`: `getRecordingMetaByPath` | ||||||||||||||||||||
| * returns `Result<RecordingMeta, String>` and fails whenever | ||||||||||||||||||||
| * `recording-meta.json` is missing or unparseable. A failed query has no | ||||||||||||||||||||
| * `data`, so treating "no data" as "still loading" leaves the editor on the | ||||||||||||||||||||
| * loading skeleton indefinitely (#1812). | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| export type EditorImportStatus = "loading" | "importing" | "ready" | "error"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export function deriveRawImportStatus(query: { | ||||||||||||||||||||
| data: unknown; | ||||||||||||||||||||
| isError: boolean; | ||||||||||||||||||||
| }): EditorImportStatus { | ||||||||||||||||||||
| if (query.isError) return "error"; | ||||||||||||||||||||
| if (!query.data) return "loading"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const meta = query.data as { status?: unknown }; | ||||||||||||||||||||
|
Comment on lines
+17
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small hardening:
Suggested change
|
||||||||||||||||||||
| if ( | ||||||||||||||||||||
| "status" in meta && | ||||||||||||||||||||
| meta.status && | ||||||||||||||||||||
| typeof meta.status === "object" && | ||||||||||||||||||||
| "status" in meta.status && | ||||||||||||||||||||
| (meta.status as { status?: unknown }).status === "InProgress" | ||||||||||||||||||||
| ) { | ||||||||||||||||||||
| return "importing"; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return "ready"; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * `lockedToImporting` latches once an import starts, so the UI doesn't flicker | ||||||||||||||||||||
| * between screens as the metadata is re-read. An error has to outrank that | ||||||||||||||||||||
| * latch: if the metadata stops being readable mid-import there is nothing left | ||||||||||||||||||||
| * to wait for, and without this the editor would stay on the import screen for | ||||||||||||||||||||
| * the same reason it used to stay on the skeleton. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| export function deriveImportStatus( | ||||||||||||||||||||
| rawStatus: EditorImportStatus, | ||||||||||||||||||||
| lockedToImporting: boolean, | ||||||||||||||||||||
| ): EditorImportStatus { | ||||||||||||||||||||
| if (rawStatus === "error") return "error"; | ||||||||||||||||||||
| if (lockedToImporting) return "importing"; | ||||||||||||||||||||
| return rawStatus; | ||||||||||||||||||||
| } | ||||||||||||||||||||
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.
EditorErrorScreenusesprojectPathfor recover/open-folder; passing""feels a bit risky. Might be nicer to gate this branch onprojectPath()like the importing/ready branches.