[codex] Structure workspace search cleanup failures (#3465)
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
a3dadc04bf
commit
2fbb0565d7
3 files changed
+65
-10
No files matched your search
@@ -151,20 +151,29 @@ export const make = Effect.gen(function* () {
|
||||
if (!(yield* RcMap.has(workspaceSearchIndexes.rcMap, normalizedCwd))) {
|
||||
return;
|
||||
}
|
||||
const recoverRefreshFailure = (
|
||||
cause:
|
||||
| WorkspaceSearchIndex.WorkspaceSearchIndexCreateFailed
|
||||
| WorkspaceSearchIndex.WorkspaceSearchIndexScanTimedOut
|
||||
| WorkspaceSearchIndex.WorkspaceSearchIndexRefreshFailed,
|
||||
) =>
|
||||
Effect.gen(function* () {
|
||||
yield* Effect.logWarning("Failed to refresh workspace search index", {
|
||||
cwd,
|
||||
cause,
|
||||
});
|
||||
yield* workspaceSearchIndexes.invalidate(normalizedCwd);
|
||||
});
|
||||
yield* Effect.gen(function* () {
|
||||
const searchIndex = yield* WorkspaceSearchIndex.WorkspaceSearchIndex;
|
||||
yield* searchIndex.refresh();
|
||||
}).pipe(
|
||||
Effect.provide(workspaceSearchIndexes.get(normalizedCwd)),
|
||||
Effect.catch((cause) =>
|
||||
Effect.gen(function* () {
|
||||
yield* Effect.logWarning("Failed to refresh workspace search index", {
|
||||
cwd,
|
||||
cause,
|
||||
});
|
||||
yield* workspaceSearchIndexes.invalidate(normalizedCwd);
|
||||
}),
|
||||
),
|
||||
Effect.catchTags({
|
||||
WorkspaceSearchIndexCreateFailed: recoverRefreshFailure,
|
||||
WorkspaceSearchIndexScanTimedOut: recoverRefreshFailure,
|
||||
WorkspaceSearchIndexRefreshFailed: recoverRefreshFailure,
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { FileFinder } from "@ff-labs/fff-node";
|
||||
import { afterEach, expect, it } from "@effect/vitest";
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import { vi } from "vite-plus/test";
|
||||
|
||||
import * as WorkspaceSearchIndex from "./WorkspaceSearchIndex.ts";
|
||||
@@ -49,6 +51,35 @@ it.effect("keeps returned FileFinder creation diagnostics out of the cause chain
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("preserves FileFinder destroy failures as structured defects", () =>
|
||||
Effect.gen(function* () {
|
||||
const cause = new Error("native destroy failed");
|
||||
const finder = {
|
||||
destroy: vi.fn(() => {
|
||||
throw cause;
|
||||
}),
|
||||
isScanning: vi.fn(() => false),
|
||||
} as unknown as FileFinder;
|
||||
vi.spyOn(FileFinder, "create").mockReturnValueOnce({ ok: true, value: finder });
|
||||
|
||||
const exit = yield* Effect.scoped(WorkspaceSearchIndex.make("/workspace/project")).pipe(
|
||||
Effect.exit,
|
||||
);
|
||||
|
||||
expect(Exit.isFailure(exit)).toBe(true);
|
||||
if (Exit.isFailure(exit)) {
|
||||
expect(Cause.hasDies(exit.cause)).toBe(true);
|
||||
const error = Cause.squash(exit.cause);
|
||||
expect(error).toBeInstanceOf(WorkspaceSearchIndex.WorkspaceSearchIndexDestroyFailed);
|
||||
expect(error).toMatchObject({
|
||||
_tag: "WorkspaceSearchIndexDestroyFailed",
|
||||
cwd: "/workspace/project",
|
||||
cause,
|
||||
});
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("preserves search and refresh failures with operation context", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
|
||||
@@ -71,6 +71,18 @@ export class WorkspaceSearchIndexRefreshFailed extends Schema.TaggedErrorClass<W
|
||||
}
|
||||
}
|
||||
|
||||
export class WorkspaceSearchIndexDestroyFailed extends Schema.TaggedErrorClass<WorkspaceSearchIndexDestroyFailed>()(
|
||||
"WorkspaceSearchIndexDestroyFailed",
|
||||
{
|
||||
cwd: Schema.String,
|
||||
cause: Schema.Defect(),
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return `Failed to destroy the workspace search index for '${this.cwd}'.`;
|
||||
}
|
||||
}
|
||||
|
||||
export type WorkspaceSearchIndexError =
|
||||
| WorkspaceSearchIndexCreateFailed
|
||||
| WorkspaceSearchIndexScanTimedOut
|
||||
@@ -201,7 +213,10 @@ const waitForScan = <E>(cwd: string, finder: FileFinder, onFailure: (cause: unkn
|
||||
|
||||
export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (cwd: string) {
|
||||
const finder = yield* Effect.acquireRelease(createFinder(cwd), (finder) =>
|
||||
Effect.sync(() => finder.destroy()),
|
||||
Effect.try({
|
||||
try: () => finder.destroy(),
|
||||
catch: (cause) => new WorkspaceSearchIndexDestroyFailed({ cwd, cause }),
|
||||
}).pipe(Effect.orDie),
|
||||
);
|
||||
yield* waitForScan(
|
||||
cwd,
|
||||
|
||||
Reference in new issue
Block a user