|
8 | 8 | */ |
9 | 9 |
|
10 | 10 | import { copyFileSync, existsSync, mkdirSync, readdirSync } from "node:fs" |
11 | | -import { dirname, join } from "node:path" |
| 11 | +import { join } from "node:path" |
12 | 12 |
|
13 | | -import { AGENTS_TARGET_DIR, getAgentsSourceDir, getPackageRoot } from "./src/paths.mjs" |
| 13 | +import { |
| 14 | + AGENTS_TARGET_DIR, |
| 15 | + getAgentsSourceDir, |
| 16 | + getErrorMessage, |
| 17 | + getPackageRoot, |
| 18 | +} from "./src/paths.mjs" |
14 | 19 |
|
15 | 20 | const packageRoot = getPackageRoot(import.meta.url) |
16 | 21 | const AGENTS_SOURCE_DIR = getAgentsSourceDir(packageRoot) |
17 | 22 |
|
18 | | -/** |
19 | | - * Returns a user-friendly error message based on the error code. |
20 | | - * |
21 | | - * Translates Node.js filesystem error codes into human-readable messages |
22 | | - * that help users understand and resolve installation issues. |
23 | | - * |
24 | | - * @param {Error & {code?: string}} error - The error object from a failed fs operation |
25 | | - * @param {string} file - The filename being copied |
26 | | - * @param {string} targetPath - The target path for the file |
27 | | - * @returns {string} A helpful error message describing the issue and potential solution |
28 | | - * |
29 | | - * @example |
30 | | - * // Permission denied error |
31 | | - * const err = Object.assign(new Error(), { code: 'EACCES' }) |
32 | | - * getErrorMessage(err, 'agent.md', '/home/user/.config/opencode/agents/agent.md') |
33 | | - * // Returns: "Permission denied. Check write permissions for /home/user/.config/opencode/agents" |
34 | | - * |
35 | | - * @example |
36 | | - * // File not found error |
37 | | - * const err = Object.assign(new Error(), { code: 'ENOENT' }) |
38 | | - * getErrorMessage(err, 'missing.md', '/target/missing.md') |
39 | | - * // Returns: "Source file not found: missing.md" |
40 | | - */ |
41 | | -function getErrorMessage(error, file, targetPath) { |
42 | | - const code = error.code |
43 | | - switch (code) { |
44 | | - case "EACCES": |
45 | | - return `Permission denied. Check write permissions for ${dirname(targetPath)}` |
46 | | - case "ENOSPC": |
47 | | - return "Disk full. Free up space and try again" |
48 | | - case "ENOENT": |
49 | | - return `Source file not found: ${file}` |
50 | | - case "EROFS": |
51 | | - return "Read-only file system. Cannot write to target directory" |
52 | | - case "EMFILE": |
53 | | - case "ENFILE": |
54 | | - return "Too many open files. Close some applications and try again" |
55 | | - default: |
56 | | - return error.message || "Unknown error" |
57 | | - } |
58 | | -} |
59 | | - |
60 | 23 | /** |
61 | 24 | * Main entry point for the postinstall script. |
62 | 25 | * |
|
0 commit comments