mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
chore: centralizing warning filters
This commit is contained in:
25
openclaw.mjs
25
openclaw.mjs
@@ -11,13 +11,36 @@ if (module.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
|
||||
}
|
||||
}
|
||||
|
||||
const isModuleNotFoundError = (err) =>
|
||||
err && typeof err === "object" && "code" in err && err.code === "ERR_MODULE_NOT_FOUND";
|
||||
|
||||
const installProcessWarningFilter = async () => {
|
||||
// Keep bootstrap warnings consistent with the TypeScript runtime.
|
||||
for (const specifier of ["./dist/warning-filter.js", "./dist/warning-filter.mjs"]) {
|
||||
try {
|
||||
const mod = await import(specifier);
|
||||
if (typeof mod.installProcessWarningFilter === "function") {
|
||||
mod.installProcessWarningFilter();
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
if (isModuleNotFoundError(err)) {
|
||||
continue;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await installProcessWarningFilter();
|
||||
|
||||
const tryImport = async (specifier) => {
|
||||
try {
|
||||
await import(specifier);
|
||||
return true;
|
||||
} catch (err) {
|
||||
// Only swallow missing-module errors; rethrow real runtime errors.
|
||||
if (err && typeof err === "object" && "code" in err && err.code === "ERR_MODULE_NOT_FOUND") {
|
||||
if (isModuleNotFoundError(err)) {
|
||||
return false;
|
||||
}
|
||||
throw err;
|
||||
|
||||
Reference in New Issue
Block a user