MCPcopy Index your code
hub / github.com/coder/mux / readWorkspaceTurnFile

Method readWorkspaceTurnFile

src/node/services/taskHandleStore.ts:239–281  ·  view source on GitHub ↗
(
    ownerWorkspaceId: string,
    handleId: string
  )

Source from the content-addressed store, hash-verified

237 }
238
239 private async readWorkspaceTurnFile(
240 ownerWorkspaceId: string,
241 handleId: string
242 ): Promise<WorkspaceTurnTaskHandleRecord | null> {
243 try {
244 const raw = await fsPromises.readFile(
245 this.getHandlePath(ownerWorkspaceId, handleId),
246 "utf-8"
247 );
248 const parsedJson = JSON.parse(raw) as unknown;
249 const parsed = WorkspaceTurnTaskHandleRecordSchema.safeParse(parsedJson);
250 if (!parsed.success) {
251 log.warn("Ignoring unreadable workspace turn task handle", {
252 ownerWorkspaceId,
253 handleId,
254 issues: parsed.error.issues,
255 });
256 return null;
257 }
258 if (
259 parsed.data.handleId !== handleId ||
260 parsed.data.ownerWorkspaceId !== ownerWorkspaceId ||
261 !isWorkspaceTurnTaskId(parsed.data.handleId)
262 ) {
263 log.warn("Ignoring mismatched workspace turn task handle", {
264 ownerWorkspaceId,
265 handleId,
266 recordOwnerWorkspaceId: parsed.data.ownerWorkspaceId,
267 recordHandleId: parsed.data.handleId,
268 });
269 return null;
270 }
271 return parsed.data as WorkspaceTurnTaskHandleRecord;
272 } catch (error) {
273 if (isErrnoWithCode(error, "ENOENT") || error instanceof SyntaxError) {
274 if (error instanceof SyntaxError) {
275 log.warn("Ignoring corrupt workspace turn task handle", { ownerWorkspaceId, handleId });
276 }
277 return null;
278 }
279 throw error;
280 }
281 }
282}

Callers 2

getWorkspaceTurnMethod · 0.95
listWorkspaceTurnsMethod · 0.95

Calls 5

getHandlePathMethod · 0.95
isErrnoWithCodeFunction · 0.90
isWorkspaceTurnTaskIdFunction · 0.85
readFileMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected