Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions apps/server/src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4943,6 +4943,69 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);

it.effect("names a missing workspace file instead of reporting a generic read failure", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const workspaceDir = yield* fs.makeTempDirectoryScoped({
prefix: "t3-ws-workspace-missing-file-",
});

yield* buildAppUnderTest();

const wsUrl = yield* getWsServerUrl("/ws");
const result = yield* Effect.scoped(
withWsRpcClient(wsUrl, (client) =>
client[WS_METHODS.projectsReadFile]({
cwd: workspaceDir,
relativePath: "components/selectors/Missing.vue",
}).pipe(Effect.result),
),
);

if (result._tag !== "Failure" || result.failure._tag !== "ProjectReadFileError") {
assert.fail("Expected a ProjectReadFileError");
}
const readError = result.failure;
assert.equal(
readError.message,
`Workspace file 'components/selectors/Missing.vue' does not exist in '${workspaceDir}'.`,
);
assert.equal(readError.cwd, workspaceDir);
assert.equal(readError.relativePath, "components/selectors/Missing.vue");
assert.equal(readError.failure, "file_not_found");
assert.isDefined(readError.cause);
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);

it.effect("does not blame the file when the workspace root itself is missing", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const parentDir = yield* fs.makeTempDirectoryScoped({
prefix: "t3-ws-workspace-missing-root-",
});
const missingWorkspace = path.join(parentDir, "gone");

yield* buildAppUnderTest();

const wsUrl = yield* getWsServerUrl("/ws");
const result = yield* Effect.scoped(
withWsRpcClient(wsUrl, (client) =>
client[WS_METHODS.projectsReadFile]({
cwd: missingWorkspace,
relativePath: "anything.txt",
}).pipe(Effect.result),
),
);

if (result._tag !== "Failure" || result.failure._tag !== "ProjectReadFileError") {
assert.fail("Expected a ProjectReadFileError");
}
assert.equal(result.failure.failure, "operation_failed");
assert.notInclude(result.failure.message, "does not exist in");
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);

it.effect("reports workspace root stat failures without relabeling them as missing", () =>
Effect.gen(function* () {
if ((yield* HostProcessPlatform) === "win32") return;
Expand Down
9 changes: 8 additions & 1 deletion apps/server/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,14 @@ function projectFileFailureContext(
return { failure: "workspace_path_outside_root" };
case "WorkspaceFileSystemOperationError":
return {
failure: "operation_failed",
// Only ENOENT means the target is genuinely absent, and a missing
// workspace root raises it through the same operation, so neither a
// permission error nor a missing root is reported as a missing file.
failure:
error.operation !== "realpath-workspace-root" &&
(error.cause as { readonly code?: unknown } | undefined)?.code === "ENOENT"
? "file_not_found"
: "operation_failed",
resolvedPath: error.resolvedPath,
operation: error.operation,
operationPath: error.operationPath,
Expand Down
5 changes: 4 additions & 1 deletion packages/contracts/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export const ProjectFileFailure = Schema.Literals([
"workspace_path_outside_root",
"resolved_path_outside_root",
"path_not_file",
"file_not_found",
"binary_file",
"operation_failed",
]);
Expand Down Expand Up @@ -257,7 +258,9 @@ export class ProjectReadFileError extends Schema.TaggedErrorClass<ProjectReadFil
...props,
message:
decodedProjectErrorMessage(props) ??
`Failed to read workspace file '${props.relativePath}' in '${props.cwd}'.`,
(props.failure === "file_not_found"
? `Workspace file '${props.relativePath}' does not exist in '${props.cwd}'.`
: `Failed to read workspace file '${props.relativePath}' in '${props.cwd}'.`),
} as any);
}
}
Expand Down
Loading