refactor: clarify diagnostics failure handling

This commit is contained in:
Gustavo Madeira Santana
2026-04-22 18:39:10 -04:00
parent 43f5a3c1f7
commit 0284787c49
2 changed files with 13 additions and 5 deletions

View File

@@ -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: {

View File

@@ -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),
}),
};
}