Skip to content

Commit 467990d

Browse files
committed
fix(error-handling): improve ENOTDIR/ENOENT errors and binary install guidance
- Split ENOTDIR and ENOENT error handling in process-lock for clearer diagnostics - ENOTDIR explains when a path component is a file instead of directory - ENOENT provides specific parent directory and mkdir command to create it - Updated bin.ts binary install guidance to use "ex:" to clarify npm is just an example
1 parent 1e31caa commit 467990d

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/bin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export async function execBin(
7575
' - Installation directory is not in system PATH\n' +
7676
'To resolve:\n' +
7777
` 1. Verify "${binPath}" is installed: which ${binPath} (Unix) or where ${binPath} (Windows)\n` +
78-
` 2. Install the binary if missing: npm install -g ${binPath}\n` +
78+
` 2. Install the binary if missing, ex: npm install -g ${binPath}\n` +
7979
' 3. Check PATH environment variable includes the binary location',
8080
) as Error & {
8181
code: string

src/process-lock.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,29 @@ class ProcessLockManager {
296296
}
297297

298298
// Handle parent path issues - not retryable.
299-
if (code === 'ENOTDIR' || code === 'ENOENT') {
299+
if (code === 'ENOTDIR') {
300+
const parentDir = lockPath.slice(0, lockPath.lastIndexOf('/'))
300301
throw new Error(
301-
`Lock parent directory does not exist or is not a directory: ${lockPath}`,
302+
`Cannot create lock directory: ${lockPath}\n` +
303+
'A path component is a file when it should be a directory.\n' +
304+
`Parent path: ${parentDir}\n` +
305+
'To resolve:\n' +
306+
` 1. Check if "${parentDir}" contains a file instead of a directory\n` +
307+
' 2. Remove any conflicting files in the path\n' +
308+
' 3. Ensure the full parent directory structure exists',
309+
{ cause: error },
310+
)
311+
}
312+
313+
if (code === 'ENOENT') {
314+
const parentDir = lockPath.slice(0, lockPath.lastIndexOf('/'))
315+
throw new Error(
316+
`Cannot create lock directory: ${lockPath}\n` +
317+
`Parent directory does not exist: ${parentDir}\n` +
318+
'To resolve:\n' +
319+
` 1. Ensure the parent directory "${parentDir}" exists\n` +
320+
` 2. Create the directory structure: mkdir -p "${parentDir}"\n` +
321+
' 3. Check filesystem permissions allow directory creation',
302322
{ cause: error },
303323
)
304324
}

0 commit comments

Comments
 (0)