Open History to see the last commit
1import * as Schema from "effect/Schema";
2
3/** A plain encoded failure crosses IPC and contextBridge without an arbitrary Error or stack. */
4export class PreviewCaptureFailure extends Schema.TaggedError<PreviewCaptureFailure>()(
5 "PreviewCaptureFailure",
6 {
7 reason: Schema.Literals([
8 "renderer-unavailable",
9 "capture-unavailable",
10 "capture-timeout",
11 "recording-conflict",
12 "capture-failed",
13 ]),
14 stage: Schema.Literals(["screenshot", "capture-page", "recording-start"]),
15 },
16) {
17 override get message(): string {
18 switch (this.reason) {
19 case "renderer-unavailable":
20 return "The preview renderer is unavailable. Reopen the preview tab before retrying.";
21 case "capture-unavailable":
22 return "The preview capture surface is unavailable. Present the target tab and check that the preview host is unlocked, its display is on and its window is restored before retrying.";
23 case "capture-timeout":
24 return `Preview capture timed out during ${this.stage}. Check the preview host's lock, display and window state before retrying.`;
25 case "recording-conflict":
26 return "A recording capture is already starting, stopping or active. Wait for it to settle, or stop the active recording before retrying.";
27 case "capture-failed":
28 return `Preview capture failed during ${this.stage}. Check the preview host and target tab before retrying.`;
29 }
30 }
31}
32
33export type PreviewCaptureFailureEncoded = Schema.Codec.Encoded<typeof PreviewCaptureFailure>;