mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 21:56:00 +00:00
better error reporting
This commit is contained in:
@@ -6,6 +6,7 @@ import _compact from 'lodash/compact';
|
||||
import { getLogger } from './getLogger';
|
||||
import { type Logger } from 'pinomin';
|
||||
import { dbNameLogCategory, isCompositeDbName, splitCompositeDbName } from './schemaInfoTools';
|
||||
import { extractErrorLogData } from './stringTools';
|
||||
|
||||
const logger = getLogger('dbAnalyser');
|
||||
|
||||
@@ -90,7 +91,9 @@ export class DatabaseAnalyser {
|
||||
}
|
||||
|
||||
async incrementalAnalysis(structure) {
|
||||
logger.info(`Performing incremental analysis, DB=${dbNameLogCategory(this.dbhan.database)}, engine=${this.driver.engine}`);
|
||||
logger.info(
|
||||
`Performing incremental analysis, DB=${dbNameLogCategory(this.dbhan.database)}, engine=${this.driver.engine}`
|
||||
);
|
||||
this.structure = structure;
|
||||
|
||||
const modifications = await this.getModifications();
|
||||
@@ -336,7 +339,7 @@ export class DatabaseAnalyser {
|
||||
this.logger.debug({ rows: res.rows.length, template }, `Loaded analyser query`);
|
||||
return res;
|
||||
} catch (err) {
|
||||
logger.error({ err, message: err.message, template }, 'Error running analyser query');
|
||||
logger.error(extractErrorLogData(err, { template }), 'Error running analyser query');
|
||||
return {
|
||||
rows: [],
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@ import _uniqBy from 'lodash/uniqBy';
|
||||
import { getLogger } from './getLogger';
|
||||
import { SqlDumper } from './SqlDumper';
|
||||
import { extendDatabaseInfo } from './structureTools';
|
||||
import { extractErrorLogData } from './stringTools';
|
||||
|
||||
const logger = getLogger('sqlGenerator');
|
||||
|
||||
@@ -85,7 +86,7 @@ export class SqlGenerator {
|
||||
}
|
||||
|
||||
private handleException = error => {
|
||||
logger.error({ error }, 'Unhandled error');
|
||||
logger.error(extractErrorLogData(error), 'Unhandled error');
|
||||
this.isUnhandledException = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ export type EditorDataType =
|
||||
const dateTimeStorageRegex =
|
||||
/^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|()|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
|
||||
|
||||
const dateTimeParseRegex = /^(\d{4})-(\d{2})-(\d{2})[Tt ](\d{2}):(\d{2}):(\d{2})(\.[0-9]+)?(([Zz])|()|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
|
||||
const dateTimeParseRegex =
|
||||
/^(\d{4})-(\d{2})-(\d{2})[Tt ](\d{2}):(\d{2}):(\d{2})(\.[0-9]+)?(([Zz])|()|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
|
||||
|
||||
export function arrayToHexString(byteArray) {
|
||||
return byteArray.reduce((output, elem) => output + ('0' + elem.toString(16)).slice(-2), '').toUpperCase();
|
||||
@@ -463,3 +464,31 @@ export function getConvertValueMenu(value, onSetValue, editorTypes?: DataEditorT
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export function extractErrorMessage(err, defaultMessage = 'Unknown error') {
|
||||
if (!err) {
|
||||
return defaultMessage;
|
||||
}
|
||||
if (_isArray(err.errors)) {
|
||||
try {
|
||||
return err.errors.map(x => x.message).join('\n');
|
||||
} catch (e2) {}
|
||||
}
|
||||
if (err.message) {
|
||||
return err.message;
|
||||
}
|
||||
const s = `${err}`;
|
||||
if (s && (!s.endsWith('Error') || s.includes(' '))) {
|
||||
return s;
|
||||
}
|
||||
return defaultMessage;
|
||||
}
|
||||
|
||||
export function extractErrorLogData(err, additionalFields = {}) {
|
||||
if (!err) return null;
|
||||
return {
|
||||
errorMessage: extractErrorMessage(err),
|
||||
errorObject: err,
|
||||
...additionalFields,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user