chore: filter noisy warnings
This commit is contained in:
@@ -5,9 +5,11 @@ import process from "node:process";
|
|||||||
|
|
||||||
import { applyCliProfileEnv, parseCliProfileArgs } from "./cli/profile.js";
|
import { applyCliProfileEnv, parseCliProfileArgs } from "./cli/profile.js";
|
||||||
import { isTruthyEnvValue } from "./infra/env.js";
|
import { isTruthyEnvValue } from "./infra/env.js";
|
||||||
|
import { installProcessWarningFilter } from "./infra/warnings.js";
|
||||||
import { attachChildProcessBridge } from "./process/child-process-bridge.js";
|
import { attachChildProcessBridge } from "./process/child-process-bridge.js";
|
||||||
|
|
||||||
process.title = "clawdbot";
|
process.title = "clawdbot";
|
||||||
|
installProcessWarningFilter();
|
||||||
|
|
||||||
if (process.argv.includes("--no-color")) {
|
if (process.argv.includes("--no-color")) {
|
||||||
process.env.NO_COLOR = "1";
|
process.env.NO_COLOR = "1";
|
||||||
|
|||||||
33
src/infra/warnings.ts
Normal file
33
src/infra/warnings.ts
Normal file
@@ -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`);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,22 +1,10 @@
|
|||||||
import { createRequire } from "node:module";
|
import { createRequire } from "node:module";
|
||||||
|
|
||||||
|
import { installProcessWarningFilter } from "../infra/warnings.js";
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
export function requireNodeSqlite(): typeof import("node:sqlite") {
|
export function requireNodeSqlite(): typeof import("node:sqlite") {
|
||||||
const onWarning = (warning: Error & { name?: string; message?: string }) => {
|
installProcessWarningFilter();
|
||||||
if (
|
return require("node:sqlite") as typeof import("node:sqlite");
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,13 @@ import type {
|
|||||||
} from "../src/channels/plugins/types.js";
|
} from "../src/channels/plugins/types.js";
|
||||||
import type { ClawdbotConfig } from "../src/config/config.js";
|
import type { ClawdbotConfig } from "../src/config/config.js";
|
||||||
import type { OutboundSendDeps } from "../src/infra/outbound/deliver.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 { setActivePluginRegistry } from "../src/plugins/runtime.js";
|
||||||
import { createTestRegistry } from "../src/test-utils/channel-plugins.js";
|
import { createTestRegistry } from "../src/test-utils/channel-plugins.js";
|
||||||
import { withIsolatedTestHome } from "./test-env";
|
import { withIsolatedTestHome } from "./test-env";
|
||||||
|
|
||||||
|
installProcessWarningFilter();
|
||||||
|
|
||||||
const testEnv = withIsolatedTestHome();
|
const testEnv = withIsolatedTestHome();
|
||||||
afterAll(() => testEnv.cleanup());
|
afterAll(() => testEnv.cleanup());
|
||||||
const pickSendFn = (id: ChannelId, deps?: OutboundSendDeps) => {
|
const pickSendFn = (id: ChannelId, deps?: OutboundSendDeps) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user