refactor: centralize strict numeric parsing

This commit is contained in:
Peter Steinberger
2026-03-08 02:52:44 +00:00
parent 3087893ef9
commit 2646739d23
11 changed files with 128 additions and 30 deletions

View File

@@ -30,6 +30,7 @@ import {
listSkillCommandsForAgents,
type HistoryEntry,
} from "openclaw/plugin-sdk/mattermost";
import { parseStrictPositiveInteger } from "../../../../src/infra/parse-finite-number.js";
import { getMattermostRuntime } from "../runtime.js";
import { resolveMattermostAccount } from "./accounts.js";
import {
@@ -348,9 +349,8 @@ export async function monitorMattermostProvider(opts: MonitorMattermostOpts = {}
// The gateway sets OPENCLAW_GATEWAY_PORT when it boots, but the config file may still contain
// a different port.
const envPortRaw = process.env.OPENCLAW_GATEWAY_PORT?.trim();
const envPort = envPortRaw ? Number.parseInt(envPortRaw, 10) : NaN;
const slashGatewayPort =
Number.isFinite(envPort) && envPort > 0 ? envPort : (cfg.gateway?.port ?? 18789);
const envPort = parseStrictPositiveInteger(envPortRaw);
const slashGatewayPort = envPort ?? cfg.gateway?.port ?? 18789;
const slashCallbackUrl = resolveCallbackUrl({
config: slashConfig,