mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
mm: disable console as it might error trying to fetch config
This commit is contained in:
@@ -5,10 +5,21 @@ const _oldConsoles = {
|
|||||||
error: console.error
|
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"]) {
|
export function disableConsoleLog(severities: ConsoleSeverity[] = ["log"]) {
|
||||||
severities.forEach((severity) => {
|
severities.forEach((severity) => {
|
||||||
console[severity] = () => null;
|
console[severity] = () => null;
|
||||||
});
|
});
|
||||||
|
return enableConsoleLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function enableConsoleLog() {
|
export function enableConsoleLog() {
|
||||||
|
|||||||
@@ -201,7 +201,10 @@ export class Repository<DB = any, TB extends keyof DB = any> implements EmitsEve
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("many error", e, compiled);
|
if (e instanceof Error) {
|
||||||
|
console.error("[ERROR] Repository.performQuery", e.message);
|
||||||
|
}
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ import {
|
|||||||
mark,
|
mark,
|
||||||
objectEach,
|
objectEach,
|
||||||
stripMark,
|
stripMark,
|
||||||
transformObject
|
transformObject,
|
||||||
|
withDisabledConsole
|
||||||
} from "core/utils";
|
} from "core/utils";
|
||||||
import {
|
import {
|
||||||
type Connection,
|
type Connection,
|
||||||
@@ -231,19 +232,23 @@ export class ModuleManager {
|
|||||||
private async fetch(): Promise<ConfigTable> {
|
private async fetch(): Promise<ConfigTable> {
|
||||||
this.logger.context("fetch").log("fetching");
|
this.logger.context("fetch").log("fetching");
|
||||||
|
|
||||||
const startTime = performance.now();
|
// disabling console log, because the table might not exist yet
|
||||||
const { data: result } = await this.repo().findOne(
|
return await withDisabledConsole(async () => {
|
||||||
{ type: "config" },
|
const startTime = performance.now();
|
||||||
{
|
const { data: result } = await this.repo().findOne(
|
||||||
sort: { by: "version", dir: "desc" }
|
{ type: "config" },
|
||||||
}
|
{
|
||||||
);
|
sort: { by: "version", dir: "desc" }
|
||||||
if (!result) {
|
}
|
||||||
throw BkndError.with("no config");
|
);
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.log("took", performance.now() - startTime, "ms", result.version).clear();
|
if (!result) {
|
||||||
return result as ConfigTable;
|
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() {
|
async save() {
|
||||||
|
|||||||
Reference in New Issue
Block a user