chore: centralizing warning filters

This commit is contained in:
Gustavo Madeira Santana
2026-02-08 05:17:59 -05:00
parent cef9bfce22
commit 3119057161
5 changed files with 160 additions and 41 deletions

View File

@@ -0,0 +1,40 @@
const warningFilterKey = Symbol.for("openclaw.warning-filter");
export type ProcessWarning = Error & {
code?: string;
name?: string;
message?: string;
};
export function shouldIgnoreWarning(warning: ProcessWarning): boolean {
if (warning.code === "DEP0040" && warning.message?.includes("punycode")) {
return true;
}
if (warning.code === "DEP0060" && warning.message?.includes("util._extend")) {
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: ProcessWarning) => {
if (shouldIgnoreWarning(warning)) {
return;
}
process.stderr.write(`${warning.stack ?? warning.toString()}\n`);
});
}