mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:40:43 +00:00
refactor: clarify diagnostics failure handling
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user