Skip to content

Commit f3b8e22

Browse files
committed
feat: add actionable suggestions to error messages (chmod, df, lsof, mount)
Signed-off-by: leocavalcante <leo@cavalcante.dev>
1 parent 7d743af commit f3b8e22

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/paths.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ export function getErrorMessage(error, file, targetPath) {
147147
const code = error.code
148148
switch (code) {
149149
case "EACCES":
150-
return `Permission denied. Check write permissions for ${dirname(targetPath)}`
150+
return `Permission denied. Check write permissions for ${dirname(targetPath)}. Try: chmod u+w ${dirname(targetPath)} or run with sudo`
151151
case "EPERM":
152-
return "Operation not permitted. The file may be in use or locked"
152+
return "Operation not permitted. The file may be in use or locked. Try: lsof <file> to check what process is using it"
153153
case "ENOSPC":
154-
return "Disk full. Free up space and try again"
154+
return "Disk full. Free up space and try again. Try: df -h to check disk usage"
155155
case "ENOENT":
156156
return `Source file not found: ${file}`
157157
case "EROFS":
158-
return "Read-only file system. Cannot write to target directory"
158+
return "Read-only file system. Cannot write to target directory. Try: mount -o remount,rw <device> <mountpoint>"
159159
case "EMFILE":
160160
case "ENFILE":
161161
return "Too many open files. Close some applications and try again"

tests/paths.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,22 @@ describe("paths.mjs exports", () => {
194194
const error = Object.assign(new Error("EACCES"), { code: "EACCES" })
195195
const result = getErrorMessage(error, testFile, testTargetPath)
196196
expect(result).toBe(
197-
"Permission denied. Check write permissions for /home/user/.config/opencode/agents",
197+
"Permission denied. Check write permissions for /home/user/.config/opencode/agents. Try: chmod u+w /home/user/.config/opencode/agents or run with sudo",
198198
)
199199
})
200200

201201
it("should return operation not permitted message for EPERM error", () => {
202202
const error = Object.assign(new Error("EPERM"), { code: "EPERM" })
203203
const result = getErrorMessage(error, testFile, testTargetPath)
204-
expect(result).toBe("Operation not permitted. The file may be in use or locked")
204+
expect(result).toBe(
205+
"Operation not permitted. The file may be in use or locked. Try: lsof <file> to check what process is using it",
206+
)
205207
})
206208

207209
it("should return disk full message for ENOSPC error", () => {
208210
const error = Object.assign(new Error("ENOSPC"), { code: "ENOSPC" })
209211
const result = getErrorMessage(error, testFile, testTargetPath)
210-
expect(result).toBe("Disk full. Free up space and try again")
212+
expect(result).toBe("Disk full. Free up space and try again. Try: df -h to check disk usage")
211213
})
212214

213215
it("should return source file not found message for ENOENT error", () => {
@@ -219,7 +221,9 @@ describe("paths.mjs exports", () => {
219221
it("should return read-only filesystem message for EROFS error", () => {
220222
const error = Object.assign(new Error("EROFS"), { code: "EROFS" })
221223
const result = getErrorMessage(error, testFile, testTargetPath)
222-
expect(result).toBe("Read-only file system. Cannot write to target directory")
224+
expect(result).toBe(
225+
"Read-only file system. Cannot write to target directory. Try: mount -o remount,rw <device> <mountpoint>",
226+
)
223227
})
224228

225229
it("should return too many open files message for EMFILE error", () => {
@@ -268,7 +272,9 @@ describe("paths.mjs exports", () => {
268272
const error = Object.assign(new Error("EACCES"), { code: "EACCES" })
269273
const deepPath = "/very/deep/nested/path/file.md"
270274
const result = getErrorMessage(error, "file.md", deepPath)
271-
expect(result).toBe("Permission denied. Check write permissions for /very/deep/nested/path")
275+
expect(result).toBe(
276+
"Permission denied. Check write permissions for /very/deep/nested/path. Try: chmod u+w /very/deep/nested/path or run with sudo",
277+
)
272278
})
273279

274280
it("should return resource temporarily unavailable message for EAGAIN error", () => {

0 commit comments

Comments
 (0)