mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 04:51:25 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -46,9 +46,13 @@ function enqueueSaveCreds(
|
||||
|
||||
function readCredsJsonRaw(filePath: string): string | null {
|
||||
try {
|
||||
if (!fsSync.existsSync(filePath)) return null;
|
||||
if (!fsSync.existsSync(filePath)) {
|
||||
return null;
|
||||
}
|
||||
const stats = fsSync.statSync(filePath);
|
||||
if (!stats.isFile() || stats.size <= 1) return null;
|
||||
if (!stats.isFile() || stats.size <= 1) {
|
||||
return null;
|
||||
}
|
||||
return fsSync.readFileSync(filePath, "utf-8");
|
||||
} catch {
|
||||
return null;
|
||||
@@ -197,7 +201,9 @@ function safeStringify(value: unknown, limit = 800): string {
|
||||
const raw = JSON.stringify(
|
||||
value,
|
||||
(_key, v) => {
|
||||
if (typeof v === "bigint") return v.toString();
|
||||
if (typeof v === "bigint") {
|
||||
return v.toString();
|
||||
}
|
||||
if (typeof v === "function") {
|
||||
const maybeName = (v as { name?: unknown }).name;
|
||||
const name =
|
||||
@@ -205,14 +211,18 @@ function safeStringify(value: unknown, limit = 800): string {
|
||||
return `[Function ${name}]`;
|
||||
}
|
||||
if (typeof v === "object" && v) {
|
||||
if (seen.has(v)) return "[Circular]";
|
||||
if (seen.has(v)) {
|
||||
return "[Circular]";
|
||||
}
|
||||
seen.add(v);
|
||||
}
|
||||
return v;
|
||||
},
|
||||
2,
|
||||
);
|
||||
if (!raw) return String(value);
|
||||
if (!raw) {
|
||||
return String(value);
|
||||
}
|
||||
return raw.length > limit ? `${raw.slice(0, limit)}…` : raw;
|
||||
} catch {
|
||||
return String(value);
|
||||
@@ -224,11 +234,15 @@ function extractBoomDetails(err: unknown): {
|
||||
error?: string;
|
||||
message?: string;
|
||||
} | null {
|
||||
if (!err || typeof err !== "object") return null;
|
||||
if (!err || typeof err !== "object") {
|
||||
return null;
|
||||
}
|
||||
const output = (err as { output?: unknown })?.output as
|
||||
| { statusCode?: unknown; payload?: unknown }
|
||||
| undefined;
|
||||
if (!output || typeof output !== "object") return null;
|
||||
if (!output || typeof output !== "object") {
|
||||
return null;
|
||||
}
|
||||
const payload = (output as { payload?: unknown }).payload as
|
||||
| { error?: unknown; message?: unknown; statusCode?: unknown }
|
||||
| undefined;
|
||||
@@ -240,14 +254,22 @@ function extractBoomDetails(err: unknown): {
|
||||
: undefined;
|
||||
const error = typeof payload?.error === "string" ? payload.error : undefined;
|
||||
const message = typeof payload?.message === "string" ? payload.message : undefined;
|
||||
if (!statusCode && !error && !message) return null;
|
||||
if (!statusCode && !error && !message) {
|
||||
return null;
|
||||
}
|
||||
return { statusCode, error, message };
|
||||
}
|
||||
|
||||
export function formatError(err: unknown): string {
|
||||
if (err instanceof Error) return err.message;
|
||||
if (typeof err === "string") return err;
|
||||
if (!err || typeof err !== "object") return String(err);
|
||||
if (err instanceof Error) {
|
||||
return err.message;
|
||||
}
|
||||
if (typeof err === "string") {
|
||||
return err;
|
||||
}
|
||||
if (!err || typeof err !== "object") {
|
||||
return String(err);
|
||||
}
|
||||
|
||||
// Baileys frequently wraps errors under `error` with a Boom-like shape.
|
||||
const boom =
|
||||
@@ -271,12 +293,22 @@ export function formatError(err: unknown): string {
|
||||
const message = messageCandidates[0];
|
||||
|
||||
const pieces: string[] = [];
|
||||
if (typeof status === "number") pieces.push(`status=${status}`);
|
||||
if (boom?.error) pieces.push(boom.error);
|
||||
if (message) pieces.push(message);
|
||||
if (codeText) pieces.push(`code=${codeText}`);
|
||||
if (typeof status === "number") {
|
||||
pieces.push(`status=${status}`);
|
||||
}
|
||||
if (boom?.error) {
|
||||
pieces.push(boom.error);
|
||||
}
|
||||
if (message) {
|
||||
pieces.push(message);
|
||||
}
|
||||
if (codeText) {
|
||||
pieces.push(`code=${codeText}`);
|
||||
}
|
||||
|
||||
if (pieces.length > 0) return pieces.join(" ");
|
||||
if (pieces.length > 0) {
|
||||
return pieces.join(" ");
|
||||
}
|
||||
return safeStringify(err);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user