Skip to content

Commit 77ff621

Browse files
SunkenInTimeclaude
andcommitted
fix(server): keep unexpected rmdir errors in worktree removal warnings
removeEmptyDirectory treated every rmdir failure as a folder that still had files, so a permission error was logged as "kept files". Only ENOTEMPTY means that now; other errors reach the existing warning with their details. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent f6d3251 commit 77ff621

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Cache from "effect/Cache";
2+
import * as Cause from "effect/Cause";
23
import * as Data from "effect/Data";
34
import * as Crypto from "effect/Crypto";
45
import * as DateTime from "effect/DateTime";
@@ -3653,7 +3654,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
36533654
*/
36543655
const removeLeftoverLinks = (
36553656
target: string,
3656-
): Effect.Effect<boolean, PlatformError.PlatformError> =>
3657+
): Effect.Effect<boolean, PlatformError.PlatformError | Cause.UnknownError> =>
36573658
Effect.gen(function* () {
36583659
if (Option.isSome(yield* fileSystem.readLink(target).pipe(Effect.option))) {
36593660
yield* fileSystem.remove(target);

‎apps/server/src/vcs/removeEmptyDirectory.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ import * as Effect from "effect/Effect";
66
/**
77
* Removes `path` only while it is an empty directory. Succeeds with false when
88
* anything else is there, including files written after the caller looked.
9+
* Other failures, such as a permission error, stay errors.
910
*/
1011
export const removeEmptyDirectory = (path: string) =>
1112
Effect.tryPromise(() => NodeFSP.rmdir(path)).pipe(
1213
Effect.as(true),
13-
Effect.orElseSucceed(() => false),
14+
Effect.catchIf(
15+
(error) => (error.cause as NodeJS.ErrnoException | undefined)?.code === "ENOTEMPTY",
16+
() => Effect.succeed(false),
17+
),
1418
);

0 commit comments

Comments
 (0)