Skip to content

Commit 8dd7e5a

Browse files
committed
Fix RPC reads missing error cause for structured file system errors
Add workspaceFileReadCompatibilityDetail() to properly map each WorkspaceFileSystemError tag to a user-visible description at the projectsReadFile RPC boundary. The previous code accessed cause.cause on all non-outside-root errors, but WorkspaceFilePathEscapeError, WorkspacePathNotFileError, and WorkspaceBinaryFileError have no cause property, producing 'undefined' in client error messages.
1 parent a7c5cce commit 8dd7e5a

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

apps/server/src/ws.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,23 @@ function workspaceBrowseCompatibilityDetail(
170170
}
171171
}
172172

173+
function workspaceFileReadCompatibilityDetail(
174+
error: WorkspaceFileSystem.WorkspaceFileSystemError,
175+
): string {
176+
switch (error._tag) {
177+
case "WorkspaceFileSystemOperationError":
178+
return legacyPlatformFailureDescription(error.cause);
179+
case "WorkspaceFilePathEscapeError":
180+
return "Workspace file path resolves outside the project root.";
181+
case "WorkspacePathNotFileError":
182+
return "Workspace path is not a file.";
183+
case "WorkspaceBinaryFileError":
184+
return "Binary files cannot be previewed as text.";
185+
default:
186+
return unexpectedCompatibilityError(error);
187+
}
188+
}
189+
173190
function projectSetupScriptCompatibilityDetail(
174191
error: ProjectSetupScriptRunner.ProjectSetupScriptRunnerError,
175192
): string {
@@ -1288,7 +1305,7 @@ const makeWsRpcLayer = (currentSession: EnvironmentAuth.AuthenticatedSession) =>
12881305
Effect.mapError((cause) => {
12891306
const message = isWorkspacePathOutsideRootError(cause)
12901307
? "Workspace file path must stay within the project root."
1291-
: `Failed to read workspace file: ${legacyPlatformFailureDescription(cause.cause)}`;
1308+
: `Failed to read workspace file: ${workspaceFileReadCompatibilityDetail(cause)}`;
12921309
return new ProjectReadFileError({ message, cause });
12931310
}),
12941311
),

0 commit comments

Comments
 (0)