meshuser: log uncaught exceptions to mesherrs

This commit is contained in:
Noah Zalev 2021-07-10 20:14:15 -04:00
parent ff4c67da7c
commit ad6ff11413
2 changed files with 12 additions and 6 deletions

View File

@ -495,15 +495,19 @@ function CreateMeshCentralServer(config, args) {
console.log('ERR: ' + datastr);
if (data.startsWith('le.challenges[tls-sni-01].loopback')) { return; } // Ignore this error output from GreenLock
if (data[data.length - 1] == '\n') { data = data.substring(0, data.length - 1); }
try {
var errlogpath = null;
if (typeof obj.args.mesherrorlogpath == 'string') { errlogpath = obj.path.join(obj.args.mesherrorlogpath, 'mesherrors.txt'); } else { errlogpath = obj.getConfigFilePath('mesherrors.txt'); }
obj.fs.appendFileSync(errlogpath, '-------- ' + new Date().toLocaleString() + ' ---- ' + getCurrentVersion() + ' --------\r\n\r\n' + data + '\r\n\r\n\r\n');
} catch (ex) { console.log('ERROR: Unable to write to mesherrors.txt.'); }
obj.logError(data);
});
childProcess.on('close', function (code) { if ((code != 0) && (code != 123)) { /* console.log("Exited with code " + code); */ } });
};
obj.logError = function (err) {
try {
var errlogpath = null;
if (typeof obj.args.mesherrorlogpath == 'string') { errlogpath = obj.path.join(obj.args.mesherrorlogpath, 'mesherrors.txt'); } else { errlogpath = obj.getConfigFilePath('mesherrors.txt'); }
obj.fs.appendFileSync(errlogpath, '-------- ' + new Date().toLocaleString() + ' ---- ' + getCurrentVersion() + ' --------\r\n\r\n' + err + '\r\n\r\n\r\n');
} catch (ex) { console.log('ERROR: Unable to write to mesherrors.txt.'); }
};
// Get current and latest MeshCentral server versions using NPM
obj.getLatestServerVersion = function (callback) {
if (callback == null) return;

View File

@ -555,7 +555,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (commandHandler != null) {
try { commandHandler(command); return;
} catch (e) {
console.log('Unhandled error while processing ' + command.action + ' for user ' + + user.name + ':\n' + e);
console.log('Unhandled error while processing ' + command.action + ' for user ' + user.name + ':\n' + e);
parent.parent.logError(e.stack);
return;
}
} else {
// console.log('Unknown action from user ' + user.name + ': ' + command.action + '.');