diff --git a/packages/api/src/controllers/archive.js b/packages/api/src/controllers/archive.js index 91286ea9..fbde9525 100644 --- a/packages/api/src/controllers/archive.js +++ b/packages/api/src/controllers/archive.js @@ -71,7 +71,7 @@ module.exports = { ...fileType('.matview.sql', 'matview.sql'), ]; } catch (err) { - logger.error('Error reading archive files', err.message); + logger.error({ err }, 'Error reading archive files'); return []; } }, diff --git a/packages/api/src/controllers/auth.js b/packages/api/src/controllers/auth.js index 1a485082..74c5ad45 100644 --- a/packages/api/src/controllers/auth.js +++ b/packages/api/src/controllers/auth.js @@ -54,7 +54,7 @@ function authMiddleware(req, res, next) { return next(); } - logger.error('Sending invalid token error', err.message); + logger.error({ err }, 'Sending invalid token error'); return unauthorizedResponse(req, res, 'invalid token'); } @@ -125,7 +125,7 @@ module.exports = { accessToken: jwt.sign({ login }, tokenSecret, { expiresIn: getTokenLifetime() }), }; } catch (err) { - logger.error('Failed active directory authentization', err); + logger.error({ err }, 'Failed active directory authentization'); return { error: err.message, }; diff --git a/packages/api/src/proc/databaseConnectionProcess.js b/packages/api/src/proc/databaseConnectionProcess.js index 4e94d627..cc94ebe8 100644 --- a/packages/api/src/proc/databaseConnectionProcess.js +++ b/packages/api/src/proc/databaseConnectionProcess.js @@ -347,9 +347,9 @@ function start() { if (handleProcessCommunication(message)) return; try { await handleMessage(message); - } catch (e) { - logger.error('Error in DB connection', e); - process.send({ msgtype: 'error', error: e.message }); + } catch (err) { + logger.error({ err }, 'Error in DB connection'); + process.send({ msgtype: 'error', error: err.message }); } }); } diff --git a/packages/api/src/proc/sshForwardProcess.js b/packages/api/src/proc/sshForwardProcess.js index 5e6480d0..8f1461a9 100644 --- a/packages/api/src/proc/sshForwardProcess.js +++ b/packages/api/src/proc/sshForwardProcess.js @@ -38,7 +38,7 @@ async function handleStart({ connection, tunnelConfig }) { tunnelConfig, }); } catch (err) { - logger.error('Error creating SSH tunnel connection:', err); + logger.error({ err }, 'Error creating SSH tunnel connection:'); process.send({ msgtype: 'error', diff --git a/packages/api/src/utility/childProcessChecker.js b/packages/api/src/utility/childProcessChecker.js index 4e39db47..c206d407 100644 --- a/packages/api/src/utility/childProcessChecker.js +++ b/packages/api/src/utility/childProcessChecker.js @@ -8,11 +8,11 @@ function childProcessChecker() { setInterval(() => { try { process.send({ msgtype: 'ping', counter: counter++ }); - } catch (ex) { + } catch (err) { // This will come once parent dies. // One way can be to check for error code ERR_IPC_CHANNEL_CLOSED // and call process.exit() - logger.error('parent died', ex); + logger.error({ err }, 'parent died'); process.exit(1); } }, 1000); diff --git a/packages/api/src/utility/directories.js b/packages/api/src/utility/directories.js index 2d84218f..c8cf5287 100644 --- a/packages/api/src/utility/directories.js +++ b/packages/api/src/utility/directories.js @@ -131,8 +131,8 @@ function migrateDataDir() { if (fs.existsSync(oldDir) && !fs.existsSync(newDir)) { fs.renameSync(oldDir, newDir); } - } catch (e) { - logger.error('Error migrating data dir:', e.message); + } catch (err) { + logger.error({ err }, 'Error migrating data dir'); } } diff --git a/packages/api/src/utility/useController.js b/packages/api/src/utility/useController.js index 0251e38d..3ff9afc8 100644 --- a/packages/api/src/utility/useController.js +++ b/packages/api/src/utility/useController.js @@ -16,7 +16,7 @@ module.exports = function useController(app, electron, route, controller) { try { controller._init(); } catch (err) { - logger.error(`Error initializing controller, exiting application`, err); + logger.error({ err }, `Error initializing controller, exiting application`); process.exit(1); } } @@ -77,16 +77,16 @@ module.exports = function useController(app, electron, route, controller) { try { const data = await controller[key]({ ...req.body, ...req.query }, req); res.json(data); - } catch (e) { - logger.error(`Error when processing route ${route}/${key}`, e); - if (e instanceof MissingCredentialsError) { + } catch (err) { + logger.error({ err }, `Error when processing route ${route}/${key}`); + if (err instanceof MissingCredentialsError) { res.json({ missingCredentials: true, apiErrorMessage: 'Missing credentials', - detail: e.detail, + detail: err.detail, }); } else { - res.status(500).json({ apiErrorMessage: e.message }); + res.status(500).json({ apiErrorMessage: err.message }); } } }); diff --git a/packages/tools/src/DatabaseAnalyser.ts b/packages/tools/src/DatabaseAnalyser.ts index d3f8d756..c3e1f24a 100644 --- a/packages/tools/src/DatabaseAnalyser.ts +++ b/packages/tools/src/DatabaseAnalyser.ts @@ -307,7 +307,7 @@ export class DatabaseAnalyser { try { return await this.driver.query(this.pool, sql); } catch (err) { - logger.error('Error running analyser query', err); + logger.error({ err }, 'Error running analyser query'); return { rows: [], }; diff --git a/packages/tools/src/SqlGenerator.ts b/packages/tools/src/SqlGenerator.ts index bdf05844..42d180fe 100644 --- a/packages/tools/src/SqlGenerator.ts +++ b/packages/tools/src/SqlGenerator.ts @@ -85,7 +85,7 @@ export class SqlGenerator { } private handleException = error => { - logger.error('Unhandled error', error); + logger.error({ error }, 'Unhandled error'); this.isUnhandledException = true; }; diff --git a/plugins/dbgate-plugin-mysql/src/backend/drivers.js b/plugins/dbgate-plugin-mysql/src/backend/drivers.js index a6b10312..22c7fe6e 100644 --- a/plugins/dbgate-plugin-mysql/src/backend/drivers.js +++ b/plugins/dbgate-plugin-mysql/src/backend/drivers.js @@ -114,7 +114,7 @@ const drivers = driverBases.map(driverBase => ({ }; const handleError = error => { - logger.error('Stream error', error); + logger.error({ error }, 'Stream error'); const { message } = error; options.info({ message, diff --git a/plugins/dbgate-plugin-postgres/src/backend/drivers.js b/plugins/dbgate-plugin-postgres/src/backend/drivers.js index d8cac6a6..edf5d1bb 100644 --- a/plugins/dbgate-plugin-postgres/src/backend/drivers.js +++ b/plugins/dbgate-plugin-postgres/src/backend/drivers.js @@ -147,7 +147,7 @@ const drivers = driverBases.map(driverBase => ({ }); query.on('error', error => { - logger.error('Stream error', error); + logger.error({ error }, 'Stream error'); const { message, position, procName } = error; let line = null; if (position) { diff --git a/plugins/dbgate-plugin-sqlite/src/backend/driver.js b/plugins/dbgate-plugin-sqlite/src/backend/driver.js index c3c24c64..c75f919e 100644 --- a/plugins/dbgate-plugin-sqlite/src/backend/driver.js +++ b/plugins/dbgate-plugin-sqlite/src/backend/driver.js @@ -106,7 +106,7 @@ const driver = { try { inTransaction(); } catch (error) { - logger.error('Stream error', error); + logger.error({ error }, 'Stream error'); const { message, procName } = error; options.info({ message,