mm: disable console as it might error trying to fetch config

This commit is contained in:
dswbx
2024-12-11 18:25:31 +01:00
parent 2395d7fe97
commit d81b3acb94
3 changed files with 33 additions and 14 deletions

View File

@@ -5,10 +5,21 @@ const _oldConsoles = {
error: console.error
};
export async function withDisabledConsole<R>(
fn: () => Promise<R>,
severities: ConsoleSeverity[] = ["log"]
): Promise<R> {
const enable = disableConsoleLog(severities);
const result = await fn();
enable();
return result;
}
export function disableConsoleLog(severities: ConsoleSeverity[] = ["log"]) {
severities.forEach((severity) => {
console[severity] = () => null;
});
return enableConsoleLog;
}
export function enableConsoleLog() {

View File

@@ -201,7 +201,10 @@ export class Repository<DB = any, TB extends keyof DB = any> implements EmitsEve
}
};
} catch (e) {
console.error("many error", e, compiled);
if (e instanceof Error) {
console.error("[ERROR] Repository.performQuery", e.message);
}
throw e;
}
}

View File

@@ -10,7 +10,8 @@ import {
mark,
objectEach,
stripMark,
transformObject
transformObject,
withDisabledConsole
} from "core/utils";
import {
type Connection,
@@ -231,6 +232,8 @@ export class ModuleManager {
private async fetch(): Promise<ConfigTable> {
this.logger.context("fetch").log("fetching");
// disabling console log, because the table might not exist yet
return await withDisabledConsole(async () => {
const startTime = performance.now();
const { data: result } = await this.repo().findOne(
{ type: "config" },
@@ -238,12 +241,14 @@ export class ModuleManager {
sort: { by: "version", dir: "desc" }
}
);
if (!result) {
throw BkndError.with("no config");
}
this.logger.log("took", performance.now() - startTime, "ms", result.version).clear();
return result as ConfigTable;
}, ["log", "error", "warn"]);
}
async save() {