Skip to content

Commit 25ad3f7

Browse files
committed
fix(error-handling): add permission error handling to removeDlxPackageSync
- Added specific error messages for EACCES/EPERM (permission denied) - Added error message for EROFS (read-only filesystem) - Improved generic error with directory path and troubleshooting guidance - Provides actionable steps: check permissions, close programs, manual removal command
1 parent 467990d commit 25ad3f7

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

src/dlx.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,32 @@ export function removeDlxPackageSync(packageName: string): void {
238238
try {
239239
rmSync(packageDir, { recursive: true, force: true })
240240
} catch (e) {
241-
throw new Error(`Failed to remove DLX package "${packageName}"`, {
242-
cause: e,
243-
})
241+
const code = (e as NodeJS.ErrnoException).code
242+
if (code === 'EACCES' || code === 'EPERM') {
243+
throw new Error(
244+
`Permission denied removing DLX package "${packageName}"\n` +
245+
`Directory: ${packageDir}\n` +
246+
'To resolve:\n' +
247+
' 1. Check file/directory permissions\n' +
248+
' 2. Close any programs using files in this directory\n' +
249+
' 3. Try running with elevated privileges if necessary\n' +
250+
` 4. Manually remove: rm -rf "${packageDir}"`,
251+
{ cause: e },
252+
)
253+
}
254+
if (code === 'EROFS') {
255+
throw new Error(
256+
`Cannot remove DLX package "${packageName}" from read-only filesystem\n` +
257+
`Directory: ${packageDir}\n` +
258+
'The filesystem is mounted read-only.',
259+
{ cause: e },
260+
)
261+
}
262+
throw new Error(
263+
`Failed to remove DLX package "${packageName}"\n` +
264+
`Directory: ${packageDir}\n` +
265+
'Check permissions and ensure no programs are using this directory.',
266+
{ cause: e },
267+
)
244268
}
245269
}

0 commit comments

Comments
 (0)