mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
chore(lint): enable stricter error rules
This commit is contained in:
@@ -63,7 +63,7 @@ export function agentLoop(
|
||||
.then((messages) => {
|
||||
stream.end(messages);
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch((error: unknown) => {
|
||||
pushLoopFailure(stream, config, error, signal?.aborted === true);
|
||||
});
|
||||
|
||||
@@ -108,7 +108,7 @@ export function agentLoopContinue(
|
||||
.then((messages) => {
|
||||
stream.end(messages);
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch((error: unknown) => {
|
||||
pushLoopFailure(stream, config, error, signal?.aborted === true);
|
||||
});
|
||||
|
||||
|
||||
@@ -588,7 +588,7 @@ export class AgentHarness<
|
||||
const hadPendingMutations = this.pendingSessionWrites.length > 0;
|
||||
await this.flushPendingSessionWrites();
|
||||
if (eventError) {
|
||||
throw eventError;
|
||||
throw toLintErrorObject(eventError, "Non-Error thrown");
|
||||
}
|
||||
await this.emitOwn({ type: "save_point", hadPendingMutations });
|
||||
return;
|
||||
@@ -1187,3 +1187,17 @@ export class AgentHarness<
|
||||
return () => handlers.delete(handler as AgentHarnessHandler);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export function err<TValue, TError>(error: TError): Result<TValue, TError> {
|
||||
/** Return the success value or throw the failure error. Intended for tests and explicit adapter boundaries. */
|
||||
export function getOrThrow<TValue, TError>(result: Result<TValue, TError>): TValue {
|
||||
if (!result.ok) {
|
||||
throw result.error;
|
||||
throw toLintErrorObject(result.error, "Non-Error thrown");
|
||||
}
|
||||
return result.value;
|
||||
}
|
||||
@@ -892,3 +892,17 @@ export interface AgentHarnessOptions<
|
||||
}
|
||||
|
||||
export type { AgentHarness } from "./agent-harness.js";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -878,7 +878,7 @@ export class GatewayClient {
|
||||
this.startTickWatch();
|
||||
this.opts.onHelloOk?.(helloOk);
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch((err: unknown) => {
|
||||
this.pendingConnectErrorDetailCode =
|
||||
err instanceof GatewayClientRequestError ? readConnectErrorDetailCode(err.details) : null;
|
||||
this.pendingConnectErrorDetails =
|
||||
|
||||
@@ -34,10 +34,10 @@ async function readChunkWithIdleTimeout(
|
||||
resolve(result);
|
||||
}
|
||||
},
|
||||
(err) => {
|
||||
(err: unknown) => {
|
||||
clear();
|
||||
if (!timedOut) {
|
||||
reject(err);
|
||||
reject(toLintErrorObject(err, "Non-Error rejection"));
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -179,3 +179,17 @@ export async function readResponseTextSnippet(
|
||||
}
|
||||
return prefix.truncated ? `${collapsed}…` : collapsed;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -252,7 +252,12 @@ class LocalEmbeddingWorkerClient {
|
||||
const abort = () => {
|
||||
this.pending.delete(id);
|
||||
this.shutdownChild();
|
||||
reject(options.signal?.reason ?? new Error("Local embedding request aborted"));
|
||||
reject(
|
||||
toLintErrorObject(
|
||||
options.signal?.reason ?? new Error("Local embedding request aborted"),
|
||||
"Non-Error rejection",
|
||||
),
|
||||
);
|
||||
};
|
||||
options.signal.addEventListener("abort", abort, { once: true });
|
||||
pending.abort = () => options.signal?.removeEventListener("abort", abort);
|
||||
@@ -362,3 +367,17 @@ export async function createLocalEmbeddingWorkerProvider(
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ process.on("message", (message) => {
|
||||
const embedPromise = provider.embedQuery("stuck");
|
||||
const embedError = embedPromise.then(
|
||||
() => undefined,
|
||||
(err) => err,
|
||||
(err: unknown) => err,
|
||||
);
|
||||
await expect
|
||||
.poll(async () => {
|
||||
|
||||
@@ -41,7 +41,7 @@ async function disposeResources(
|
||||
}
|
||||
}
|
||||
if (firstError) {
|
||||
throw firstError;
|
||||
throw toLintErrorObject(firstError, "Non-Error thrown");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,3 +181,17 @@ export async function createLocalEmbeddingProviderInProcess(
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ export async function retryAsync<T>(
|
||||
await sleep(resolveSafeTimeoutDelayMs(initialDelayMs * 2 ** i, { minMs: 0 }));
|
||||
}
|
||||
}
|
||||
throw lastErr ?? new Error("Retry failed");
|
||||
throw toLintErrorObject(lastErr ?? new Error("Retry failed"), "Non-Error thrown");
|
||||
}
|
||||
|
||||
const options = attemptsOrOptions;
|
||||
@@ -151,5 +151,19 @@ export async function retryAsync<T>(
|
||||
}
|
||||
}
|
||||
|
||||
throw lastErr ?? new Error("Retry failed");
|
||||
throw toLintErrorObject(lastErr ?? new Error("Retry failed"), "Non-Error thrown");
|
||||
}
|
||||
|
||||
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