Skip to content

Commit d9042ba

Browse files
authored
fix: return original error when can't rename overwrite (#61)
1 parent 115cfc4 commit d9042ba

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,15 @@ async function forceSymlink (
8888
warn = `Symlink wanted name was occupied by directory or file. Old entity removed: "${parentDir}${pathLib.sep}{${pathLib.basename(path)}".`
8989
} else {
9090
const ignore = `.ignored_${pathLib.basename(path)}`
91-
await renameOverwrite(path, pathLib.join(parentDir, ignore))
91+
try {
92+
await renameOverwrite(path, pathLib.join(parentDir, ignore))
93+
} catch (error) {
94+
if (util.types.isNativeError(error) && 'code' in error && error.code === 'ENOENT') {
95+
throw initialErr
96+
}
97+
throw error
98+
}
99+
92100
warn = `Symlink wanted name was occupied by directory or file. Old entity moved: "${parentDir}${pathLib.sep}{${pathLib.basename(path)} => ${ignore}".`
93101
}
94102

@@ -185,7 +193,14 @@ function forceSymlinkSync (
185193
warn = `Symlink wanted name was occupied by directory or file. Old entity removed: "${parentDir}${pathLib.sep}{${pathLib.basename(path)}".`
186194
} else {
187195
const ignore = `.ignored_${pathLib.basename(path)}`
188-
renameOverwrite.sync(path, pathLib.join(parentDir, ignore))
196+
try {
197+
renameOverwrite.sync(path, pathLib.join(parentDir, ignore))
198+
} catch (error) {
199+
if (util.types.isNativeError(error) && 'code' in error && error.code === 'ENOENT') {
200+
throw initialErr
201+
}
202+
throw error
203+
}
189204
warn = `Symlink wanted name was occupied by directory or file. Old entity moved: "${parentDir}${pathLib.sep}{${pathLib.basename(path)} => ${ignore}".`
190205
}
191206

0 commit comments

Comments
 (0)