chore: filter noisy warnings
This commit is contained in:
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`);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user