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 23, 18:00 UTC
fix(web): show attempted paths in file preview errors (#15628)
maria committed
Oct 6, 2026 at 20:50 UTC
876f8656e310f365eab98678e68bcc45615fec7f
5 files changed
+137
-3
apps/web/src/components/files/FilePreviewPanel.test.ts
+47
@@ -1,3 +1,5 @@
1
+import { ProjectReadFileError } from "@t3tools/contracts";
2
+import * as Schema from "effect/Schema";
3
import { describe, expect, it } from "vite-plus/test";
4
5
import {
@@ -6,12 +8,57 @@ import {
8
remapFileCommentAnnotations,
9
} from "./fileCommentAnnotations";
10
import {
11
+ filePreviewReadErrorMessage,
12
isMarkdownPreviewFile,
13
resolveFilePreviewPath,
14
setMarkdownTaskChecked,
15
shouldShowFileExplorer,
16
} from "./filePreviewMode";
17
18
+const decodeReadError = Schema.decodeSync(ProjectReadFileError);
19
+
20
+describe("file preview read errors", () => {
21
+ it.each([
22
+ ["path_not_file", "The path is a directory or special file, not a regular file."],
23
+ ["binary_file", "The file is binary and cannot be displayed as text."],
24
+ ["workspace_path_outside_root", "The requested path is outside the workspace."],
25
+ ["resolved_path_outside_root", "The path resolves to a location outside the workspace."],
26
+ [
27
+ "operation_failed",
28
+ "The file could not be accessed or read. It may be missing or inaccessible.",
29
+ ],
30
+ ] as const)("describes %s without revealing the platform cause", (failure, message) => {
31
+ const error = new ProjectReadFileError({
32
+ cwd: "/workspace",
33
+ relativePath: "workspace/outline.md",
34
+ failure,
35
+ operation: "realpath-target",
36
+ resolvedPath: "/workspace/workspace/outline.md",
37
+ cause: new Error("EACCES: sensitive platform detail"),
38
+ });
39
+ expect(filePreviewReadErrorMessage(error)).toBe(message);
40
+ });
41
+
42
+ it("distinguishes an inaccessible workspace from an inaccessible file", () => {
43
+ const error = new ProjectReadFileError({
44
+ cwd: "/workspace",
45
+ relativePath: "outline.md",
46
+ failure: "operation_failed",
47
+ operation: "realpath-workspace-root",
48
+ operationPath: "/workspace",
49
+ });
50
+ expect(filePreviewReadErrorMessage(error)).toBe("The workspace folder could not be accessed.");
51
+ });
52
+
53
+ it("preserves the public message from older servers", () => {
54
+ const error = decodeReadError({
55
+ _tag: "ProjectReadFileError",
56
+ message: "Legacy file read failure.",
57
+ });
58
+ expect(filePreviewReadErrorMessage(error)).toBe("Legacy file read failure.");
59
+ });
60
+});
61
+
62
describe("file comment annotations", () => {
63
it("normalizes and formats selected line ranges", () => {
64
expect(normalizeFileCommentRange({ start: 16, end: 7 })).toEqual({
apps/web/src/components/files/FilePreviewPanel.tsx
+25
-2
@@ -82,6 +82,7 @@ import { resolveCenteredFileLineScrollTop } from "./fileLineReveal";
82
import { DiffCommentAnnotation } from "../diffs/DiffCommentAnnotation";
83
import { projectFileCacheKey, projectFileEditorCacheKey } from "./fileContentRevision";
84
import {
85
+ filePreviewReadErrorMessage,
86
isMarkdownPreviewFile,
87
resolveFilePreviewPath,
88
setMarkdownTaskChecked,
@@ -957,6 +958,7 @@ export default function FilePreviewPanel({
958
relativePath,
959
attachment === undefined && relativePath !== null,
960
);
961
+ const attemptedPath = file.readError?.resolvedPath ?? file.readError?.operationPath;
962
// A chat link cannot tell a folder from a file, so a folder arrives here as
963
// a file surface and the read fails. Keep the breadcrumbs, drop the preview
964
// pane, and let the tree fill the surface with the folder revealed. Mutation
@@ -1236,8 +1238,29 @@ export default function FilePreviewPanel({
1238
workspaceMutationId={workspaceMutationId}
1239
/>
1240
) : relativePath && file.error && file.data === null ? (
1239
- <div className="flex min-h-0 flex-1 items-center justify-center px-6 text-center text-xs leading-relaxed text-destructive">
1240
- {file.error}
1241
+ <div role="alert" className="flex min-h-0 flex-1 flex-col overflow-auto">
1242
+ <div className="my-auto flex shrink-0 flex-col gap-3 px-6 py-6 text-center text-xs leading-relaxed">
1243
+ <p className="text-destructive">
1244
+ {file.readError ? filePreviewReadErrorMessage(file.readError) : file.error}
1245
+ </p>
1246
+ {attemptedPath ? (
1247
+ <p className="text-muted-foreground">
1248
+ Attempted path
1249
+ <code className="block break-all font-mono text-foreground select-all">
1250
+ {attemptedPath}
1251
+ </code>
1252
+ </p>
1253
+ ) : null}
1254
+ {!isHostFile ? (
1255
+ <p className="text-muted-foreground">
1256
+ Workspace folder:{" "}
1257
+ <code className="break-all font-mono select-all">
1258
+ {file.readError?.cwd ?? cwd}
1259
+ </code>
1260
+ . Check the link's path or locate the file in Files.
1261
+ </p>
1262
+ ) : null}
1263
+ </div>
1264
</div>
1265
) : relativePath && file.data === null ? (
1266
<div className="flex min-h-0 flex-1 items-center justify-center text-muted-foreground">
apps/web/src/components/files/filePreviewMode.ts
+22
@@ -1,4 +1,5 @@
1
import { workspaceRelativeFilePath } from "@t3tools/client-runtime/markdown-links";
2
+import type { ProjectReadFileError } from "@t3tools/contracts";
3
import { isAbsolutePath } from "~/terminal-links";
4
5
/** Resolve workspace links before choosing between the explorer and a file preview. */
@@ -9,6 +10,27 @@ export function resolveFilePreviewPath(path: string | null, cwd: string): string
10
11
export const isMarkdownPreviewFile = (path: string): boolean => /\.(?:md|mdx)$/i.test(path);
12
13
+/** Describe existing failure codes without exposing the underlying platform cause. */
14
+export function filePreviewReadErrorMessage(error: ProjectReadFileError): string {
15
+ switch (error.failure) {
16
+ case "path_not_file":
17
+ return "The path is a directory or special file, not a regular file.";
18
+ case "binary_file":
19
+ return "The file is binary and cannot be displayed as text.";
20
+ case "workspace_path_outside_root":
21
+ return "The requested path is outside the workspace.";
22
+ case "resolved_path_outside_root":
23
+ return "The path resolves to a location outside the workspace.";
24
+ case "operation_failed":
25
+ // A realpath failure can mean a missing path, permissions, or another I/O error.
26
+ return error.operation === "realpath-workspace-root"
27
+ ? "The workspace folder could not be accessed."
28
+ : "The file could not be accessed or read. It may be missing or inaccessible.";
29
+ default:
30
+ return error.message;
31
+ }
32
+}
33
+
34
export function shouldShowFileExplorer(input: {
35
readonly relativePath: string | null;
36
readonly explorerOpen: boolean;
apps/web/src/components/files/projectFilesQueryState.test.tsx
+39
@@ -5,6 +5,7 @@ import {
5
type ProjectReadFileResult,
6
} from "@t3tools/contracts";
7
import * as Effect from "effect/Effect";
8
+import * as Schema from "effect/Schema";
9
import { Atom, AtomRegistry } from "effect/reactivity";
10
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
11
@@ -79,6 +80,7 @@ import { useWorkspaceMutationRefresh } from "~/hooks/useWorkspaceMutationRefresh
80
import { useProjectEntriesQuery, useProjectFileQuery } from "./projectFilesQueryState";
81
82
const environmentId = EnvironmentId.make("environment-1");
83
+const decodeReadError = Schema.decodeSync(ProjectReadFileError);
84
85
function deferred<A>() {
86
let resolve!: (value: A) => void;
@@ -137,6 +139,7 @@ describe("project query refresh", () => {
139
const render = (mutationId: string | null) => {
140
reactHooks.beginRender();
141
const query = useProjectFileQuery(environmentId, "/repo", "src/preview.ts");
142
+ expect(query.readError).toBeNull();
143
renderedContents = query.data?.contents ?? null;
144
useWorkspaceMutationRefresh({
145
mutationId,
@@ -245,6 +248,7 @@ describe("project query refresh", () => {
248
await flushEffects();
249
250
expect(projectMocks.readFile).not.toHaveBeenCalled();
251
+ expect(query.readError).toBeNull();
252
expect(requests).toHaveLength(0);
253
} finally {
254
registry.dispose();
@@ -273,6 +277,7 @@ describe("project query refresh", () => {
277
reactHooks.beginRender();
278
const query = useProjectFileQuery(environmentId, "/repo", "assets.png");
279
expect(query.isNotFile).toBe(true);
280
+ expect(query.readError?.failure).toBe("path_not_file");
281
expect(query.data).toBeNull();
282
} finally {
283
unmount();
@@ -302,6 +307,40 @@ describe("project query refresh", () => {
307
reactHooks.beginRender();
308
const query = useProjectFileQuery(environmentId, "/repo", ".agents/skills");
309
expect(query.isNotFile).toBe(true);
310
+ expect(query.readError?.failure).toBe("path_not_file");
311
+ expect(query.data).toBeNull();
312
+ } finally {
313
+ unmount();
314
+ registry.dispose();
315
+ atomHooks.registry = null;
316
+ }
317
+ });
318
+
319
+ it("retains decoded read failure context for the connected environment", async () => {
320
+ const error = decodeReadError({
321
+ _tag: "ProjectReadFileError",
322
+ cwd: "C:\\workspace",
323
+ relativePath: "workspace/outline.md",
324
+ failure: "operation_failed",
325
+ operation: "realpath-target",
326
+ operationPath: "C:\\workspace\\workspace\\outline.md",
327
+ resolvedPath: "C:\\workspace\\workspace\\outline.md",
328
+ message: "Failed to read workspace file.",
329
+ });
330
+ const readAtom = Atom.make(Effect.fail(error));
331
+ const registry = AtomRegistry.make();
332
+ const unmount = registry.mount(readAtom);
333
+ projectMocks.readFile.mockReturnValue(readAtom);
334
+ projectMocks.optimisticFile.mockReturnValue(Atom.make(null));
335
+ atomHooks.registry = registry;
336
+
337
+ try {
338
+ await flushEffects();
339
+ reactHooks.beginRender();
340
+ const query = useProjectFileQuery(environmentId, "C:\\workspace", "workspace/outline.md");
341
+ expect(query.readError).toBe(error);
342
+ expect(query.error).toBe(error.message);
343
+ expect(query.isNotFile).toBe(false);
344
expect(query.data).toBeNull();
345
} finally {
346
unmount();
apps/web/src/components/files/projectFilesQueryState.ts
+4
-1
@@ -37,6 +37,7 @@ interface ProjectQueryState<A> {
37
}
38
39
interface ProjectFileQueryState extends ProjectQueryState<ProjectReadFileResult> {
40
+ readonly readError: ProjectReadFileError | null;
41
/** The path exists but is not a regular file, typically a directory. */
42
readonly isNotFile: boolean;
43
}
@@ -217,11 +218,13 @@ export function useProjectFileQuery(
218
);
219
const optimisticFile = relativePath === null ? null : optimisticResult;
220
const cause = failureCause(result);
221
+ const readError = isProjectReadFileError(cause) ? cause : null;
222
223
return {
224
data: optimisticFile?.data ?? data,
225
error: errorMessage(cause),
224
- isNotFile: isProjectReadFileError(cause) && cause.failure === "path_not_file",
226
+ readError,
227
+ isNotFile: readError?.failure === "path_not_file",
228
isPending: result.waiting,
229
refresh,
230
};