diff --git a/src/logging/diagnostic-stability-bundle.test.ts b/src/logging/diagnostic-stability-bundle.test.ts index 4b68c5f0eea..432443ae944 100644 --- a/src/logging/diagnostic-stability-bundle.test.ts +++ b/src/logging/diagnostic-stability-bundle.test.ts @@ -121,9 +121,11 @@ describe("diagnostic stability bundles", () => { }, ); - expect(result.status).toBe("written"); - const bundle = readBundle(result.status === "written" ? result.path : ""); - const raw = fs.readFileSync(result.status === "written" ? result.path : "", "utf8"); + if (result.status !== "written") { + throw new Error(`expected written bundle, got ${result.status}`); + } + const bundle = readBundle(result.path); + const raw = fs.readFileSync(result.path, "utf8"); expect(bundle).toMatchObject({ reason: "gateway.restart_startup_failed", error: { diff --git a/src/logging/diagnostic-support-export.ts b/src/logging/diagnostic-support-export.ts index b401385bc7f..cb3a49ea61e 100644 --- a/src/logging/diagnostic-support-export.ts +++ b/src/logging/diagnostic-support-export.ts @@ -291,6 +291,13 @@ function isMissingPathError(error: unknown): boolean { return error.code === "ENOENT" || error.code === "ENOTDIR"; } +function configReadErrorMessage(error: unknown, stat?: fs.Stats): string | undefined { + if (!stat && isMissingPathError(error)) { + return undefined; + } + return error instanceof Error ? error.message : String(error); +} + function readConfigExport(options: { configPath: string; env: NodeJS.ProcessEnv; @@ -316,13 +323,12 @@ function readConfigExport(options: { sanitized: sanitizeConfigDetails(parsed.parsed, options), }; } catch (error) { - const errorMessage = error instanceof Error ? error.message : String(error); return { shape: configShapeReadFailure({ configPath: redactedConfigPath, redaction: options, stat, - error: !stat && isMissingPathError(error) ? undefined : errorMessage, + error: configReadErrorMessage(error, stat), }), }; }