fixed error logging

This commit is contained in:
Jan Prochazka 2023-01-21 18:00:59 +01:00
parent cc0f05168d
commit d4f0882054
12 changed files with 22 additions and 22 deletions

View File

@ -71,7 +71,7 @@ module.exports = {
...fileType('.matview.sql', 'matview.sql'), ...fileType('.matview.sql', 'matview.sql'),
]; ];
} catch (err) { } catch (err) {
logger.error('Error reading archive files', err.message); logger.error({ err }, 'Error reading archive files');
return []; return [];
} }
}, },

View File

@ -54,7 +54,7 @@ function authMiddleware(req, res, next) {
return next(); return next();
} }
logger.error('Sending invalid token error', err.message); logger.error({ err }, 'Sending invalid token error');
return unauthorizedResponse(req, res, 'invalid token'); return unauthorizedResponse(req, res, 'invalid token');
} }
@ -125,7 +125,7 @@ module.exports = {
accessToken: jwt.sign({ login }, tokenSecret, { expiresIn: getTokenLifetime() }), accessToken: jwt.sign({ login }, tokenSecret, { expiresIn: getTokenLifetime() }),
}; };
} catch (err) { } catch (err) {
logger.error('Failed active directory authentization', err); logger.error({ err }, 'Failed active directory authentization');
return { return {
error: err.message, error: err.message,
}; };

View File

@ -347,9 +347,9 @@ function start() {
if (handleProcessCommunication(message)) return; if (handleProcessCommunication(message)) return;
try { try {
await handleMessage(message); await handleMessage(message);
} catch (e) { } catch (err) {
logger.error('Error in DB connection', e); logger.error({ err }, 'Error in DB connection');
process.send({ msgtype: 'error', error: e.message }); process.send({ msgtype: 'error', error: err.message });
} }
}); });
} }

View File

@ -38,7 +38,7 @@ async function handleStart({ connection, tunnelConfig }) {
tunnelConfig, tunnelConfig,
}); });
} catch (err) { } catch (err) {
logger.error('Error creating SSH tunnel connection:', err); logger.error({ err }, 'Error creating SSH tunnel connection:');
process.send({ process.send({
msgtype: 'error', msgtype: 'error',

View File

@ -8,11 +8,11 @@ function childProcessChecker() {
setInterval(() => { setInterval(() => {
try { try {
process.send({ msgtype: 'ping', counter: counter++ }); process.send({ msgtype: 'ping', counter: counter++ });
} catch (ex) { } catch (err) {
// This will come once parent dies. // This will come once parent dies.
// One way can be to check for error code ERR_IPC_CHANNEL_CLOSED // One way can be to check for error code ERR_IPC_CHANNEL_CLOSED
// and call process.exit() // and call process.exit()
logger.error('parent died', ex); logger.error({ err }, 'parent died');
process.exit(1); process.exit(1);
} }
}, 1000); }, 1000);

View File

@ -131,8 +131,8 @@ function migrateDataDir() {
if (fs.existsSync(oldDir) && !fs.existsSync(newDir)) { if (fs.existsSync(oldDir) && !fs.existsSync(newDir)) {
fs.renameSync(oldDir, newDir); fs.renameSync(oldDir, newDir);
} }
} catch (e) { } catch (err) {
logger.error('Error migrating data dir:', e.message); logger.error({ err }, 'Error migrating data dir');
} }
} }

View File

@ -16,7 +16,7 @@ module.exports = function useController(app, electron, route, controller) {
try { try {
controller._init(); controller._init();
} catch (err) { } catch (err) {
logger.error(`Error initializing controller, exiting application`, err); logger.error({ err }, `Error initializing controller, exiting application`);
process.exit(1); process.exit(1);
} }
} }
@ -77,16 +77,16 @@ module.exports = function useController(app, electron, route, controller) {
try { try {
const data = await controller[key]({ ...req.body, ...req.query }, req); const data = await controller[key]({ ...req.body, ...req.query }, req);
res.json(data); res.json(data);
} catch (e) { } catch (err) {
logger.error(`Error when processing route ${route}/${key}`, e); logger.error({ err }, `Error when processing route ${route}/${key}`);
if (e instanceof MissingCredentialsError) { if (err instanceof MissingCredentialsError) {
res.json({ res.json({
missingCredentials: true, missingCredentials: true,
apiErrorMessage: 'Missing credentials', apiErrorMessage: 'Missing credentials',
detail: e.detail, detail: err.detail,
}); });
} else { } else {
res.status(500).json({ apiErrorMessage: e.message }); res.status(500).json({ apiErrorMessage: err.message });
} }
} }
}); });

View File

@ -307,7 +307,7 @@ export class DatabaseAnalyser {
try { try {
return await this.driver.query(this.pool, sql); return await this.driver.query(this.pool, sql);
} catch (err) { } catch (err) {
logger.error('Error running analyser query', err); logger.error({ err }, 'Error running analyser query');
return { return {
rows: [], rows: [],
}; };

View File

@ -85,7 +85,7 @@ export class SqlGenerator {
} }
private handleException = error => { private handleException = error => {
logger.error('Unhandled error', error); logger.error({ error }, 'Unhandled error');
this.isUnhandledException = true; this.isUnhandledException = true;
}; };

View File

@ -114,7 +114,7 @@ const drivers = driverBases.map(driverBase => ({
}; };
const handleError = error => { const handleError = error => {
logger.error('Stream error', error); logger.error({ error }, 'Stream error');
const { message } = error; const { message } = error;
options.info({ options.info({
message, message,

View File

@ -147,7 +147,7 @@ const drivers = driverBases.map(driverBase => ({
}); });
query.on('error', error => { query.on('error', error => {
logger.error('Stream error', error); logger.error({ error }, 'Stream error');
const { message, position, procName } = error; const { message, position, procName } = error;
let line = null; let line = null;
if (position) { if (position) {

View File

@ -106,7 +106,7 @@ const driver = {
try { try {
inTransaction(); inTransaction();
} catch (error) { } catch (error) {
logger.error('Stream error', error); logger.error({ error }, 'Stream error');
const { message, procName } = error; const { message, procName } = error;
options.info({ options.info({
message, message,