mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-28 00:43:57 +00:00
refactor: dedupe browser and memory host error helpers
This commit is contained in:
@@ -3,6 +3,7 @@ import path from "node:path";
|
||||
import type { BrowserProfileConfig, OpenClawConfig } from "../config/config.js";
|
||||
import { loadConfig, writeConfigFile } from "../config/config.js";
|
||||
import { deriveDefaultBrowserCdpPortRange } from "../config/port-defaults.js";
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import { resolveUserPath } from "../utils.js";
|
||||
import { assertCdpEndpointAllowed } from "./cdp.helpers.js";
|
||||
import { resolveOpenClawUserDataDir } from "./chrome.js";
|
||||
@@ -127,7 +128,7 @@ export function createBrowserProfilesService(ctx: BrowserRouteContext) {
|
||||
parsed = parseHttpUrl(rawCdpUrl, "browser.profiles.cdpUrl");
|
||||
await assertCdpEndpointAllowed(parsed.normalized, state.resolved.ssrfPolicy);
|
||||
} catch (err) {
|
||||
throw new BrowserValidationError(err instanceof Error ? err.message : String(err));
|
||||
throw new BrowserValidationError(formatErrorMessage(err));
|
||||
}
|
||||
if (driver === "existing-session") {
|
||||
throw new BrowserValidationError(
|
||||
|
||||
@@ -459,7 +459,7 @@ async function connectBrowser(cdpUrl: string): Promise<ConnectedBrowser> {
|
||||
} catch (err) {
|
||||
lastErr = err;
|
||||
// Don't retry rate-limit errors; retrying worsens the 429.
|
||||
const errMsg = err instanceof Error ? err.message : String(err);
|
||||
const errMsg = formatErrorMessage(err);
|
||||
if (errMsg.includes("rate limit")) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import type { BrowserActRequest, BrowserFormField } from "./client-actions-core.js";
|
||||
import { DEFAULT_FILL_FIELD_TYPE } from "./form-fields.js";
|
||||
import { DEFAULT_UPLOAD_DIR, resolveStrictExistingPathsWithinRoot } from "./paths.js";
|
||||
@@ -880,7 +881,7 @@ export async function batchViaPlaywright(opts: {
|
||||
await executeSingleAction(action, opts.cdpUrl, opts.targetId, opts.evaluateEnabled, depth);
|
||||
results.push({ ok: true });
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
const message = formatErrorMessage(err);
|
||||
results.push({ ok: false, error: message });
|
||||
if (opts.stopOnError !== false) {
|
||||
break;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import { parseRoleRef } from "./pw-role-snapshot.js";
|
||||
|
||||
let nextUploadArmId = 0;
|
||||
@@ -49,7 +50,7 @@ export function normalizeTimeoutMs(timeoutMs: number | undefined, fallback: numb
|
||||
}
|
||||
|
||||
export function toAIFriendlyError(error: unknown, selector: string): Error {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const message = formatErrorMessage(error);
|
||||
|
||||
if (message.includes("strict mode violation")) {
|
||||
const countMatch = message.match(/resolved to (\d+) elements/);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { formatErrorMessage } from "../../infra/errors.js";
|
||||
import {
|
||||
clickChromeMcpElement,
|
||||
closeChromeMcpTab,
|
||||
@@ -1085,7 +1086,7 @@ export function registerBrowserAgentActRoutes(
|
||||
try {
|
||||
actions = Array.isArray(body.actions) ? body.actions.map(normalizeBatchAction) : [];
|
||||
} catch (err) {
|
||||
return jsonError(res, 400, err instanceof Error ? err.message : String(err));
|
||||
return jsonError(res, 400, formatErrorMessage(err));
|
||||
}
|
||||
if (!actions.length) {
|
||||
return jsonError(res, 400, "actions are required");
|
||||
|
||||
Reference in New Issue
Block a user