mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 15:48:28 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -37,13 +37,17 @@ const TRANSIENT_NETWORK_CODES = new Set([
|
||||
]);
|
||||
|
||||
function getErrorCause(err: unknown): unknown {
|
||||
if (!err || typeof err !== "object") return undefined;
|
||||
if (!err || typeof err !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
return (err as { cause?: unknown }).cause;
|
||||
}
|
||||
|
||||
function extractErrorCodeWithCause(err: unknown): string | undefined {
|
||||
const direct = extractErrorCode(err);
|
||||
if (direct) return direct;
|
||||
if (direct) {
|
||||
return direct;
|
||||
}
|
||||
return extractErrorCode(getErrorCause(err));
|
||||
}
|
||||
|
||||
@@ -52,12 +56,18 @@ function extractErrorCodeWithCause(err: unknown): string | undefined {
|
||||
* These are typically intentional cancellations (e.g., during shutdown) and shouldn't crash.
|
||||
*/
|
||||
export function isAbortError(err: unknown): boolean {
|
||||
if (!err || typeof err !== "object") return false;
|
||||
if (!err || typeof err !== "object") {
|
||||
return false;
|
||||
}
|
||||
const name = "name" in err ? String(err.name) : "";
|
||||
if (name === "AbortError") return true;
|
||||
if (name === "AbortError") {
|
||||
return true;
|
||||
}
|
||||
// Check for "This operation was aborted" message from Node's undici
|
||||
const message = "message" in err && typeof err.message === "string" ? err.message : "";
|
||||
if (message === "This operation was aborted") return true;
|
||||
if (message === "This operation was aborted") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -76,15 +86,21 @@ function isConfigError(err: unknown): boolean {
|
||||
* These are typically temporary connectivity issues that will resolve on their own.
|
||||
*/
|
||||
export function isTransientNetworkError(err: unknown): boolean {
|
||||
if (!err) return false;
|
||||
if (!err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const code = extractErrorCodeWithCause(err);
|
||||
if (code && TRANSIENT_NETWORK_CODES.has(code)) return true;
|
||||
if (code && TRANSIENT_NETWORK_CODES.has(code)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// "fetch failed" TypeError from undici (Node's native fetch)
|
||||
if (err instanceof TypeError && err.message === "fetch failed") {
|
||||
const cause = getErrorCause(err);
|
||||
if (cause) return isTransientNetworkError(cause);
|
||||
if (cause) {
|
||||
return isTransientNetworkError(cause);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -112,7 +128,9 @@ export function registerUnhandledRejectionHandler(handler: UnhandledRejectionHan
|
||||
export function isUnhandledRejectionHandled(reason: unknown): boolean {
|
||||
for (const handler of handlers) {
|
||||
try {
|
||||
if (handler(reason)) return true;
|
||||
if (handler(reason)) {
|
||||
return true;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[openclaw] Unhandled rejection handler failed:",
|
||||
@@ -125,7 +143,9 @@ export function isUnhandledRejectionHandled(reason: unknown): boolean {
|
||||
|
||||
export function installUnhandledRejectionHandler(): void {
|
||||
process.on("unhandledRejection", (reason, _promise) => {
|
||||
if (isUnhandledRejectionHandled(reason)) return;
|
||||
if (isUnhandledRejectionHandled(reason)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// AbortError is typically an intentional cancellation (e.g., during shutdown)
|
||||
// Log it but don't crash - these are expected during graceful shutdown
|
||||
|
||||
Reference in New Issue
Block a user