From 5482803547d416c9aca82c7ff705a9d93d0dd8e8 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 24 Jan 2026 10:48:33 +0000 Subject: [PATCH] chore: filter noisy warnings --- src/entry.ts | 2 ++ src/infra/warnings.ts | 33 +++++++++++++++++++++++++++++++++ src/memory/sqlite.ts | 20 ++++---------------- test/setup.ts | 3 +++ 4 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 src/infra/warnings.ts diff --git a/src/entry.ts b/src/entry.ts index b09922ff0..b1a575954 100644 --- a/src/entry.ts +++ b/src/entry.ts @@ -5,9 +5,11 @@ import process from "node:process"; import { applyCliProfileEnv, parseCliProfileArgs } from "./cli/profile.js"; import { isTruthyEnvValue } from "./infra/env.js"; +import { installProcessWarningFilter } from "./infra/warnings.js"; import { attachChildProcessBridge } from "./process/child-process-bridge.js"; process.title = "clawdbot"; +installProcessWarningFilter(); if (process.argv.includes("--no-color")) { process.env.NO_COLOR = "1"; diff --git a/src/infra/warnings.ts b/src/infra/warnings.ts new file mode 100644 index 000000000..862112adf --- /dev/null +++ b/src/infra/warnings.ts @@ -0,0 +1,33 @@ +const warningFilterKey = Symbol.for("clawdbot.warning-filter"); + +type Warning = Error & { + code?: string; + name?: string; + message?: string; +}; + +function shouldIgnoreWarning(warning: Warning): boolean { + if (warning.code === "DEP0040" && warning.message?.includes("punycode")) { + return true; + } + if ( + warning.name === "ExperimentalWarning" && + warning.message?.includes("SQLite is an experimental feature") + ) { + return true; + } + return false; +} + +export function installProcessWarningFilter(): void { + const globalState = globalThis as typeof globalThis & { + [warningFilterKey]?: { installed: boolean }; + }; + if (globalState[warningFilterKey]?.installed) return; + globalState[warningFilterKey] = { installed: true }; + + process.on("warning", (warning: Warning) => { + if (shouldIgnoreWarning(warning)) return; + process.stderr.write(`${warning.stack ?? warning.toString()}\n`); + }); +} diff --git a/src/memory/sqlite.ts b/src/memory/sqlite.ts index 0680259fe..98b006941 100644 --- a/src/memory/sqlite.ts +++ b/src/memory/sqlite.ts @@ -1,22 +1,10 @@ import { createRequire } from "node:module"; +import { installProcessWarningFilter } from "../infra/warnings.js"; + const require = createRequire(import.meta.url); export function requireNodeSqlite(): typeof import("node:sqlite") { - const onWarning = (warning: Error & { name?: string; message?: string }) => { - if ( - warning.name === "ExperimentalWarning" && - warning.message?.includes("SQLite is an experimental feature") - ) { - return; - } - process.stderr.write(`${warning.stack ?? warning.toString()}\n`); - }; - - process.on("warning", onWarning); - try { - return require("node:sqlite") as typeof import("node:sqlite"); - } finally { - process.off("warning", onWarning); - } + installProcessWarningFilter(); + return require("node:sqlite") as typeof import("node:sqlite"); } diff --git a/test/setup.ts b/test/setup.ts index 02cd85ef1..b96e8d611 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -7,10 +7,13 @@ import type { } from "../src/channels/plugins/types.js"; import type { ClawdbotConfig } from "../src/config/config.js"; import type { OutboundSendDeps } from "../src/infra/outbound/deliver.js"; +import { installProcessWarningFilter } from "../src/infra/warnings.js"; import { setActivePluginRegistry } from "../src/plugins/runtime.js"; import { createTestRegistry } from "../src/test-utils/channel-plugins.js"; import { withIsolatedTestHome } from "./test-env"; +installProcessWarningFilter(); + const testEnv = withIsolatedTestHome(); afterAll(() => testEnv.cleanup()); const pickSendFn = (id: ChannelId, deps?: OutboundSendDeps) => {