Errors now show app frames highlighted with relative paths and library frames collapsed, both in ANSI on the console and as a styled HTML page in the browser. Process-level uncaughtException/unhandledRejection handlers also use the formatter. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
51 lines
976 B
TypeScript
51 lines
976 B
TypeScript
import nunjucks from "nunjucks";
|
|
import { db, migrate, migrationStatus } from "../database";
|
|
import { formatError, formatErrorHtml } from "../errors";
|
|
import { getLogs, log } from "../logging";
|
|
|
|
// FIXME: This doesn't belong here; move it somewhere else.
|
|
const conf = {
|
|
templateEngine: () => {
|
|
return {
|
|
renderTemplate: (template: string, context: object) => {
|
|
return nunjucks.renderString(template, context);
|
|
},
|
|
};
|
|
},
|
|
};
|
|
|
|
const database = {
|
|
db,
|
|
migrate,
|
|
migrationStatus,
|
|
};
|
|
|
|
const logging = {
|
|
log,
|
|
getLogs,
|
|
};
|
|
|
|
const random = {
|
|
randomNumber: () => {
|
|
return Math.random();
|
|
},
|
|
};
|
|
|
|
const misc = {
|
|
sleep: (ms: number) => {
|
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
},
|
|
};
|
|
|
|
// Keep this asciibetically sorted
|
|
const core = {
|
|
conf,
|
|
database,
|
|
errors: { formatError, formatErrorHtml },
|
|
logging,
|
|
misc,
|
|
random,
|
|
};
|
|
|
|
export { core };
|