Preserve original causes in directory access errors
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
976ff6fcdf
commit
5badab515f
2 files changed
+30
-6
No files matched your search
+10
-2
@@ -343,8 +343,16 @@ export function validateLaunchDirectory(launchCwd: string): string {
|
||||
let stats: fs.Stats;
|
||||
try {
|
||||
stats = fs.statSync(resolved);
|
||||
} catch {
|
||||
throw new Error(`Launch directory does not exist: ${resolved}`);
|
||||
} catch (error) {
|
||||
const code = (error as NodeJS.ErrnoException | undefined)?.code;
|
||||
if (code && code !== "ENOENT") {
|
||||
throw new Error(`Failed to access launch directory: ${resolved} (${code})`, {
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
throw new Error(`Launch directory does not exist: ${resolved}`, {
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
|
||||
if (!stats.isDirectory()) {
|
||||
|
||||
@@ -325,8 +325,16 @@ function resolveExistingDirectory(targetPath: string, label: string): string {
|
||||
let stats: fs.Stats;
|
||||
try {
|
||||
stats = fs.statSync(candidate);
|
||||
} catch {
|
||||
throw new Error(`${label} does not exist: ${candidate}`);
|
||||
} catch (error) {
|
||||
const code = (error as NodeJS.ErrnoException | undefined)?.code;
|
||||
if (code && code !== "ENOENT") {
|
||||
throw new Error(`Failed to access ${label.toLowerCase()}: ${candidate} (${code})`, {
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
throw new Error(`${label} does not exist: ${candidate}`, {
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
|
||||
if (!stats.isDirectory()) {
|
||||
@@ -347,8 +355,16 @@ function resolveExistingDirectoryFromBase(
|
||||
let stats: fs.Stats;
|
||||
try {
|
||||
stats = fs.statSync(candidate);
|
||||
} catch {
|
||||
throw new Error(`${label} does not exist: ${candidate}`);
|
||||
} catch (error) {
|
||||
const code = (error as NodeJS.ErrnoException | undefined)?.code;
|
||||
if (code && code !== "ENOENT") {
|
||||
throw new Error(`Failed to access ${label.toLowerCase()}: ${candidate} (${code})`, {
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
throw new Error(`${label} does not exist: ${candidate}`, {
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
|
||||
if (!stats.isDirectory()) {
|
||||
|
||||
Reference in new issue
Block a user