From 5badab515fed9a0086613ea899887824bfcd24fd Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 01:30:04 +0000 Subject: [PATCH] Preserve original causes in directory access errors Co-authored-by: Theo Browne --- apps/t3/src/cli.ts | 12 ++++++++++-- apps/t3/src/runtimeApiServer.ts | 24 ++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/apps/t3/src/cli.ts b/apps/t3/src/cli.ts index dc2198fa11..0328b75bac 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -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()) { diff --git a/apps/t3/src/runtimeApiServer.ts b/apps/t3/src/runtimeApiServer.ts index 6808d9b9f6..035aa8bdf9 100644 --- a/apps/t3/src/runtimeApiServer.ts +++ b/apps/t3/src/runtimeApiServer.ts @@ -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()) {