The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { PreviewCaptureFailure } from "@t3tools/contracts"; |
| 2 | import * as Cause from "effect/Cause"; |
| 3 | import type { PreviewManagerError } from "./Manager.ts"; |
| 4 | |
| 5 | /** Classify before Electron replaces a rejected IPC Error with its message. */ |
| 6 | export function normalizeCaptureFailure( |
| 7 | error: PreviewManagerError, |
| 8 | stage: PreviewCaptureFailure["stage"], |
| 9 | ): PreviewCaptureFailure { |
| 10 | let reason: PreviewCaptureFailure["reason"] = "capture-failed"; |
| 11 | switch (error._tag) { |
| 12 | case "PreviewTabNotFoundError": |
| 13 | case "PreviewWebContentsNotFoundError": |
| 14 | case "PreviewMainWindowClosedError": |
| 15 | reason = "renderer-unavailable"; |
| 16 | break; |
| 17 | case "PreviewWebviewNotInitializedError": |
| 18 | case "PreviewRecordingCaptureUnavailableError": |
| 19 | reason = "capture-unavailable"; |
| 20 | break; |
| 21 | case "PreviewRecordingArmConflictError": |
| 22 | reason = "recording-conflict"; |
| 23 | break; |
| 24 | case "PreviewOperationError": |
| 25 | if (error.operation === "captureScreenshot.capturePage") { |
| 26 | stage = "capture-page"; |
| 27 | if ( |
| 28 | error.cause instanceof Error && |
| 29 | error.cause.message === "Current display surface not available for capture" |
| 30 | ) { |
| 31 | reason = "capture-unavailable"; |
| 32 | } |
| 33 | } |
| 34 | if (Cause.isTimeoutError(error.cause)) reason = "capture-timeout"; |
| 35 | break; |
| 36 | } |
| 37 | return new PreviewCaptureFailure({ reason, stage }); |
| 38 | } |