mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 05:40:23 +00:00
refactor: dedupe core error helpers
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
export { isRecord } from "../utils.js";
|
||||
|
||||
export function isNonEmptyString(value: unknown): value is string {
|
||||
@@ -61,22 +62,5 @@ export function writeTextFileAtomic(pathname: string, value: string, mode = 0o60
|
||||
}
|
||||
|
||||
export function describeUnknownError(err: unknown): string {
|
||||
if (err instanceof Error && err.message.trim().length > 0) {
|
||||
return err.message;
|
||||
}
|
||||
if (typeof err === "string" && err.trim().length > 0) {
|
||||
return err;
|
||||
}
|
||||
if (typeof err === "number" || typeof err === "bigint") {
|
||||
return err.toString();
|
||||
}
|
||||
if (typeof err === "boolean") {
|
||||
return err ? "true" : "false";
|
||||
}
|
||||
try {
|
||||
const serialized = JSON.stringify(err);
|
||||
return serialized ?? "unknown error";
|
||||
} catch {
|
||||
return "unknown error";
|
||||
}
|
||||
return formatErrorMessage(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user