mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 19:56:00 +00:00
better error reporting
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
"start:api:auth": "yarn workspace dbgate-api start:auth | pino-pretty",
|
||||
"start:api:dblogin": "yarn workspace dbgate-api start:dblogin | pino-pretty",
|
||||
"start:api:storage": "yarn workspace dbgate-api start:storage | pino-pretty",
|
||||
"start:api:storage:built": "yarn workspace dbgate-api start:storage:built | pino-pretty",
|
||||
"sync:pro": "cd sync && yarn start",
|
||||
"start:web": "yarn workspace dbgate-web dev",
|
||||
"start:sqltree": "yarn workspace dbgate-sqltree start",
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
"start:dblogin": "env-cmd -f env/dblogin/.env node src/index.js --listen-api",
|
||||
"start:filedb": "env-cmd node src/index.js /home/jena/test/chinook/Chinook.db --listen-api",
|
||||
"start:storage": "env-cmd -f env/storage/.env node src/index.js --listen-api",
|
||||
"start:storage:built": "env-cmd -f env/storage/.env cross-env DEVMODE= BUILTWEBMODE=1 node dist/bundle.js --listen-api",
|
||||
"start:singleconn": "env-cmd node src/index.js --server localhost --user root --port 3307 --engine mysql@dbgate-plugin-mysql --password test --listen-api",
|
||||
"ts": "tsc",
|
||||
"build": "webpack"
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
const { setLogConfig, getLogger, setLoggerName } = require('dbgate-tools');
|
||||
const { setLogConfig, getLogger, setLoggerName, extractErrorLogData } = require('dbgate-tools');
|
||||
const processArgs = require('./utility/processArgs');
|
||||
const fs = require('fs');
|
||||
const moment = require('moment');
|
||||
const path = require('path');
|
||||
const { logsdir, setLogsFilePath, getLogsFilePath } = require('./utility/directories');
|
||||
const { createLogger } = require('pinomin');
|
||||
|
||||
const logger = getLogger('apiIndex');
|
||||
|
||||
process.on('uncaughtException', err => {
|
||||
logger.fatal(extractErrorLogData(err), 'Uncaught exception');
|
||||
});
|
||||
|
||||
if (processArgs.startProcess) {
|
||||
setLoggerName(processArgs.startProcess.replace(/Process$/, ''));
|
||||
|
||||
@@ -71,6 +71,9 @@ function packagedPluginsDir() {
|
||||
if (platformInfo.isDevMode) {
|
||||
return path.resolve(__dirname, '../../../../plugins');
|
||||
}
|
||||
if (platformInfo.isBuiltWebMode) {
|
||||
return path.resolve(__dirname, '../../plugins');
|
||||
}
|
||||
if (platformInfo.isDocker) {
|
||||
return '/home/dbgate-docker/plugins';
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ const isMac = platform === 'darwin';
|
||||
const isLinux = platform === 'linux';
|
||||
const isDocker = fs.existsSync('/home/dbgate-docker/public');
|
||||
const isDevMode = process.env.DEVMODE == '1';
|
||||
const isBuiltWebMode = process.env.BUILTWEBMODE == '1';
|
||||
const isNpmDist = !!global['IS_NPM_DIST'];
|
||||
const isDbModel = !!global['IS_DB_MODEL'];
|
||||
const isForkedApi = processArgs.isForkedApi;
|
||||
|
||||
@@ -484,11 +484,19 @@ export function extractErrorMessage(err, defaultMessage = 'Unknown error') {
|
||||
return defaultMessage;
|
||||
}
|
||||
|
||||
export function extractErrorStackTrace(err) {
|
||||
const { stack } = err;
|
||||
if (!_isString(stack)) return undefined;
|
||||
if (stack.length > 1000) return stack.substring(0, 1000) + '... (truncated)';
|
||||
return stack;
|
||||
}
|
||||
|
||||
export function extractErrorLogData(err, additionalFields = {}) {
|
||||
if (!err) return null;
|
||||
return {
|
||||
errorMessage: extractErrorMessage(err),
|
||||
errorObject: err,
|
||||
errorStack: extractErrorStackTrace(err),
|
||||
...additionalFields,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user