Skip to content

Commit 06107c1

Browse files
committed
feat: add EEXIST and EISDIR error handling to getErrorMessage
Signed-off-by: leocavalcante <leo@cavalcante.dev>
1 parent f5934cb commit 06107c1

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/paths.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export function getErrorMessage(error, file, targetPath) {
7373
case "EMFILE":
7474
case "ENFILE":
7575
return "Too many open files. Close some applications and try again"
76+
case "EEXIST":
77+
return `Target already exists: ${targetPath}`
78+
case "EISDIR":
79+
return `Expected a file but found a directory: ${targetPath}`
7680
default:
7781
return error.message || "Unknown error"
7882
}

tests/paths.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ describe("paths.mjs exports", () => {
141141
expect(result).toBe("Too many open files. Close some applications and try again")
142142
})
143143

144+
it("should return target exists message for EEXIST error", () => {
145+
const error = Object.assign(new Error("EEXIST"), { code: "EEXIST" })
146+
const result = getErrorMessage(error, testFile, testTargetPath)
147+
expect(result).toBe(`Target already exists: ${testTargetPath}`)
148+
})
149+
150+
it("should return is directory message for EISDIR error", () => {
151+
const error = Object.assign(new Error("EISDIR"), { code: "EISDIR" })
152+
const result = getErrorMessage(error, testFile, testTargetPath)
153+
expect(result).toBe(`Expected a file but found a directory: ${testTargetPath}`)
154+
})
155+
144156
it("should return error message for unknown error codes", () => {
145157
const error = Object.assign(new Error("Something went wrong"), { code: "UNKNOWN" })
146158
const result = getErrorMessage(error, testFile, testTargetPath)

tests/plugin.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, expect, it } from "bun:test"
2+
import type { PluginInput } from "@opencode-ai/plugin"
23
import { OpenCoderPlugin } from "../src/plugin"
34

45
describe("OpenCoderPlugin", () => {
@@ -7,17 +8,17 @@ describe("OpenCoderPlugin", () => {
78
})
89

910
it("should return a hooks object when called", async () => {
10-
// Create a mock context (minimal implementation)
11+
// Create a mock context (minimal implementation for testing)
1112
const mockContext = {
1213
project: {},
1314
client: {},
1415
$: () => {},
1516
directory: "/tmp",
1617
worktree: "/tmp",
1718
serverUrl: new URL("http://localhost:3000"),
18-
}
19+
} as unknown as PluginInput
1920

20-
const result = await OpenCoderPlugin(mockContext as Parameters<typeof OpenCoderPlugin>[0])
21+
const result = await OpenCoderPlugin(mockContext)
2122

2223
expect(result).toBeDefined()
2324
expect(typeof result).toBe("object")
@@ -31,9 +32,9 @@ describe("OpenCoderPlugin", () => {
3132
directory: "/tmp",
3233
worktree: "/tmp",
3334
serverUrl: new URL("http://localhost:3000"),
34-
}
35+
} as unknown as PluginInput
3536

36-
const result = await OpenCoderPlugin(mockContext as Parameters<typeof OpenCoderPlugin>[0])
37+
const result = await OpenCoderPlugin(mockContext)
3738

3839
expect(Object.keys(result)).toHaveLength(0)
3940
})

0 commit comments

Comments
 (0)