Skip to content

Commit f6d4562

Browse files
authored
refactor(signal): reuse shared error coercion (#113544)
1 parent b459836 commit f6d4562

2 files changed

Lines changed: 6 additions & 33 deletions

File tree

‎extensions/signal/src/client-container.ts‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import nodePath from "node:path";
10+
import { toErrorObject } from "openclaw/plugin-sdk/error-runtime";
1011
import { resolveFetch } from "openclaw/plugin-sdk/fetch-runtime";
1112
import { detectMime, parseMediaContentLength } from "openclaw/plugin-sdk/media-runtime";
1213
import {
@@ -461,7 +462,7 @@ export async function streamContainerEvents(params: {
461462
}
462463
settled = true;
463464
cleanup();
464-
reject(toLintErrorObject(error, "Signal WebSocket receive handler failed"));
465+
reject(toErrorObject(error, "Signal WebSocket receive handler failed"));
465466
};
466467

467468
try {
@@ -470,7 +471,7 @@ export async function streamContainerEvents(params: {
470471
logError(
471472
`[signal-ws] failed to create WebSocket: ${err instanceof Error ? err.message : String(err)}`,
472473
);
473-
reject(toLintErrorObject(err, "Non-Error rejection"));
474+
reject(toErrorObject(err, "Non-Error rejection"));
474475
return;
475476
}
476477

@@ -948,18 +949,4 @@ export async function containerRpcRequest<T = unknown>(
948949
throw new Error(`Unsupported container RPC method: ${method}`);
949950
}
950951
}
951-
952-
function toLintErrorObject(value: unknown, fallbackMessage: string): Error {
953-
if (value instanceof Error) {
954-
return value;
955-
}
956-
if (typeof value === "string") {
957-
return new Error(value);
958-
}
959-
const error = new Error(fallbackMessage, { cause: value });
960-
if ((typeof value === "object" && value !== null) || typeof value === "function") {
961-
Object.assign(error, value);
962-
}
963-
return error;
964-
}
965952
/* oxlint-disable max-lines -- TODO: split this grandfathered oversized file. */

‎extensions/signal/src/client.ts‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Buffer } from "node:buffer";
33
import http, { type ClientRequest, type IncomingMessage } from "node:http";
44
import https from "node:https";
55
import { generateSecureUuid } from "openclaw/plugin-sdk/core";
6-
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
6+
import { formatErrorMessage, toErrorObject } from "openclaw/plugin-sdk/error-runtime";
77
import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
88

99
export type SignalRpcOptions = {
@@ -145,7 +145,7 @@ function requestSignalHttpText(
145145
}
146146
settled = true;
147147
cleanup();
148-
reject(toLintErrorObject(error, "Non-Error rejection"));
148+
reject(toErrorObject(error, "Non-Error rejection"));
149149
};
150150
const resolveOnce = (response: SignalHttpResponse) => {
151151
if (settled) {
@@ -297,7 +297,7 @@ function openSignalEventStream(
297297
}
298298
settled = true;
299299
cleanup();
300-
reject(toLintErrorObject(error, "Non-Error rejection"));
300+
reject(toErrorObject(error, "Non-Error rejection"));
301301
};
302302
const request: ClientRequest = client.request(
303303
url,
@@ -441,17 +441,3 @@ export async function streamSignalEvents(params: {
441441

442442
await flushEvent();
443443
}
444-
445-
function toLintErrorObject(value: unknown, fallbackMessage: string): Error {
446-
if (value instanceof Error) {
447-
return value;
448-
}
449-
if (typeof value === "string") {
450-
return new Error(value);
451-
}
452-
const error = new Error(fallbackMessage, { cause: value });
453-
if ((typeof value === "object" && value !== null) || typeof value === "function") {
454-
Object.assign(error, value);
455-
}
456-
return error;
457-
}

0 commit comments

Comments
 (0)