@devries-cameron20 / t3code Mirror · read-only / commits / 71608142c2
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 24, 22:45 UTC

[codex] Split preferred editor precondition errors (#3324)

Co-authored-by: codex <codex@users.noreply.github.com>

Julius Marminge committed Jun 20, 2026 at 10:59 UTC 71608142c27136a5ba0551fe9ed52ceeaad22ee4
1 file changed +35 -10
apps/web/src/editorPreferences.ts
+35 -10
@@ -1,11 +1,11 @@
1 -import { EDITORS, EditorId, type EnvironmentId } from "@t3tools/contracts";
1 +import { EDITORS, EditorId, EnvironmentId } from "@t3tools/contracts";
2 import {
3 mapAtomCommandResult,
4 type AtomCommandFailure,
5 type AtomCommandResult,
6 } from "@t3tools/client-runtime/state/runtime";
7 import * as Cause from "effect/Cause";
8 -import * as Data from "effect/Data";
8 +import * as Schema from "effect/Schema";
9 import { AsyncResult } from "effect/unstable/reactivity";
10 import { getLocalStorageItem, setLocalStorageItem, useLocalStorage } from "./hooks/useLocalStorage";
11 import { useCallback, useMemo } from "react";
@@ -14,11 +14,29 @@ import { useAtomCommand } from "./state/use-atom-command";
14
15 const LAST_EDITOR_KEY = "t3code:last-editor";
16
17 -export class PreferredEditorUnavailableError extends Data.TaggedError(
17 +export class PreferredEditorEnvironmentRequiredError extends Schema.TaggedErrorClass<PreferredEditorEnvironmentRequiredError>()(
18 + "PreferredEditorEnvironmentRequiredError",
19 + {
20 + targetPath: Schema.String,
21 + },
22 +) {
23 + override get message(): string {
24 + return `Cannot open ${this.targetPath} because no environment is selected.`;
25 + }
26 +}
27 +
28 +export class PreferredEditorUnavailableError extends Schema.TaggedErrorClass<PreferredEditorUnavailableError>()(
29 "PreferredEditorUnavailableError",
19 -)<{
20 - readonly message: string;
21 -}> {}
30 + {
31 + environmentId: EnvironmentId,
32 + targetPath: Schema.String,
33 + availableEditorIds: Schema.Array(EditorId),
34 + },
35 +) {
36 + override get message(): string {
37 + return `No available editor can open ${this.targetPath} in environment ${this.environmentId}.`;
38 + }
39 +}
40
41 export function usePreferredEditor(availableEditors: ReadonlyArray<EditorId>) {
42 const [lastEditor, setLastEditor] = useLocalStorage(LAST_EDITOR_KEY, null, EditorId);
@@ -55,13 +73,18 @@ export function useOpenInPreferredEditor(
73 async (
74 targetPath: string,
75 ): Promise<
58 - AtomCommandResult<EditorId, OpenInEditorError | PreferredEditorUnavailableError>
76 + AtomCommandResult<
77 + EditorId,
78 + | OpenInEditorError
79 + | PreferredEditorEnvironmentRequiredError
80 + | PreferredEditorUnavailableError
81 + >
82 > => {
83 if (environmentId === null) {
84 return AsyncResult.failure(
85 Cause.fail(
63 - new PreferredEditorUnavailableError({
64 - message: "No environment is selected.",
86 + new PreferredEditorEnvironmentRequiredError({
87 + targetPath,
88 }),
89 ),
90 );
@@ -71,7 +94,9 @@ export function useOpenInPreferredEditor(
94 return AsyncResult.failure(
95 Cause.fail(
96 new PreferredEditorUnavailableError({
74 - message: "No available editors found.",
97 + environmentId,
98 + targetPath,
99 + availableEditorIds: availableEditors,
100 }),
101 ),
102 );