better error reporting

This commit is contained in:
SPRINX0\prochazka
2024-10-01 12:15:22 +02:00
parent 29a66bfcb0
commit ef23b786ac
23 changed files with 99 additions and 69 deletions

View File

@@ -3,7 +3,7 @@ const { fork } = require('child_process');
const { handleProcessCommunication } = require('./processComm');
const processArgs = require('../utility/processArgs');
const pipeForkLogs = require('./pipeForkLogs');
const { getLogger } = require('dbgate-tools');
const { getLogger, extractErrorLogData } = require('dbgate-tools');
const logger = getLogger('DatastoreProxy');
class DatastoreProxy {
@@ -73,7 +73,7 @@ class DatastoreProxy {
try {
this.subprocess.send({ msgtype: 'read', msgid, offset, limit });
} catch (err) {
logger.error({ err }, 'Error getting rows');
logger.error(extractErrorLogData(err), 'Error getting rows');
this.subprocess = null;
}
});
@@ -87,7 +87,7 @@ class DatastoreProxy {
try {
this.subprocess.send({ msgtype: 'notify', msgid });
} catch (err) {
logger.error({ err }, 'Error notifying subprocess');
logger.error(extractErrorLogData(err), 'Error notifying subprocess');
this.subprocess = null;
}
});

View File

@@ -1,4 +1,4 @@
const { getLogger } = require('dbgate-tools');
const { getLogger, extractErrorLogData } = require('dbgate-tools');
const logger = getLogger('childProcessChecked');
@@ -12,7 +12,7 @@ function childProcessChecker() {
// 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({ err }, 'parent died');
logger.error(extractErrorLogData(err), 'parent died');
process.exit(1);
}
}, 1000);

View File

@@ -5,7 +5,7 @@ const AsyncLock = require('async-lock');
const lock = new AsyncLock();
const { fork } = require('child_process');
const processArgs = require('../utility/processArgs');
const { getLogger } = require('dbgate-tools');
const { getLogger, extractErrorLogData } = require('dbgate-tools');
const pipeForkLogs = require('./pipeForkLogs');
const logger = getLogger('sshTunnel');
@@ -40,7 +40,7 @@ function callForwardProcess(connection, tunnelConfig, tunnelCacheKey) {
tunnelConfig,
});
} catch (err) {
logger.error({ err }, 'Error connecting SSH');
logger.error(extractErrorLogData(err), 'Error connecting SSH');
}
return new Promise((resolve, reject) => {
subprocess.on('message', resp => {

View File

@@ -1,5 +1,5 @@
const crypto = require('crypto');
const { getLogger } = require('dbgate-tools');
const { getLogger, extractErrorLogData } = require('dbgate-tools');
const { getSshTunnel } = require('./sshTunnel');
const logger = getLogger('sshTunnelProxy');
@@ -10,7 +10,7 @@ async function handleGetSshTunnelRequest({ msgid, connection }, subprocess) {
try {
subprocess.send({ msgtype: 'getsshtunnel-response', msgid, response });
} catch (err) {
logger.error({ err }, 'Error sending to SSH tunnel');
logger.error(extractErrorLogData(err), 'Error sending to SSH tunnel');
}
}

View File

@@ -2,7 +2,7 @@ const _ = require('lodash');
const express = require('express');
const getExpressPath = require('./getExpressPath');
const { MissingCredentialsError } = require('./exceptions');
const { getLogger } = require('dbgate-tools');
const { getLogger, extractErrorLogData } = require('dbgate-tools');
const logger = getLogger('useController');
/**
@@ -16,7 +16,7 @@ module.exports = function useController(app, electron, route, controller) {
try {
controller._init();
} catch (err) {
logger.error({ err }, `Error initializing controller, exiting application`);
logger.error(extractErrorLogData(err), `Error initializing controller, exiting application`);
process.exit(1);
}
}
@@ -78,7 +78,7 @@ module.exports = function useController(app, electron, route, controller) {
const data = await controller[key]({ ...req.body, ...req.query }, req);
res.json(data);
} catch (err) {
logger.error({ err }, `Error when processing route ${route}/${key}`);
logger.error(extractErrorLogData(err), `Error when processing route ${route}/${key}`);
if (err instanceof MissingCredentialsError) {
res.json({
missingCredentials: true,