mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
refactor(signal): reuse shared error coercion (#113544)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
import nodePath from "node:path";
|
||||
import { toErrorObject } from "openclaw/plugin-sdk/error-runtime";
|
||||
import { resolveFetch } from "openclaw/plugin-sdk/fetch-runtime";
|
||||
import { detectMime, parseMediaContentLength } from "openclaw/plugin-sdk/media-runtime";
|
||||
import {
|
||||
@@ -461,7 +462,7 @@ export async function streamContainerEvents(params: {
|
||||
}
|
||||
settled = true;
|
||||
cleanup();
|
||||
reject(toLintErrorObject(error, "Signal WebSocket receive handler failed"));
|
||||
reject(toErrorObject(error, "Signal WebSocket receive handler failed"));
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -470,7 +471,7 @@ export async function streamContainerEvents(params: {
|
||||
logError(
|
||||
`[signal-ws] failed to create WebSocket: ${err instanceof Error ? err.message : String(err)}`,
|
||||
);
|
||||
reject(toLintErrorObject(err, "Non-Error rejection"));
|
||||
reject(toErrorObject(err, "Non-Error rejection"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -948,18 +949,4 @@ export async function containerRpcRequest<T = unknown>(
|
||||
throw new Error(`Unsupported container RPC method: ${method}`);
|
||||
}
|
||||
}
|
||||
|
||||
function toLintErrorObject(value: unknown, fallbackMessage: string): Error {
|
||||
if (value instanceof Error) {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
return new Error(value);
|
||||
}
|
||||
const error = new Error(fallbackMessage, { cause: value });
|
||||
if ((typeof value === "object" && value !== null) || typeof value === "function") {
|
||||
Object.assign(error, value);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
/* oxlint-disable max-lines -- TODO: split this grandfathered oversized file. */
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Buffer } from "node:buffer";
|
||||
import http, { type ClientRequest, type IncomingMessage } from "node:http";
|
||||
import https from "node:https";
|
||||
import { generateSecureUuid } from "openclaw/plugin-sdk/core";
|
||||
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
||||
import { formatErrorMessage, toErrorObject } from "openclaw/plugin-sdk/error-runtime";
|
||||
import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
|
||||
|
||||
export type SignalRpcOptions = {
|
||||
@@ -145,7 +145,7 @@ function requestSignalHttpText(
|
||||
}
|
||||
settled = true;
|
||||
cleanup();
|
||||
reject(toLintErrorObject(error, "Non-Error rejection"));
|
||||
reject(toErrorObject(error, "Non-Error rejection"));
|
||||
};
|
||||
const resolveOnce = (response: SignalHttpResponse) => {
|
||||
if (settled) {
|
||||
@@ -297,7 +297,7 @@ function openSignalEventStream(
|
||||
}
|
||||
settled = true;
|
||||
cleanup();
|
||||
reject(toLintErrorObject(error, "Non-Error rejection"));
|
||||
reject(toErrorObject(error, "Non-Error rejection"));
|
||||
};
|
||||
const request: ClientRequest = client.request(
|
||||
url,
|
||||
@@ -441,17 +441,3 @@ export async function streamSignalEvents(params: {
|
||||
|
||||
await flushEvent();
|
||||
}
|
||||
|
||||
function toLintErrorObject(value: unknown, fallbackMessage: string): Error {
|
||||
if (value instanceof Error) {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
return new Error(value);
|
||||
}
|
||||
const error = new Error(fallbackMessage, { cause: value });
|
||||
if ((typeof value === "object" && value !== null) || typeof value === "function") {
|
||||
Object.assign(error, value);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user