From a0c1eab587d423c1c541cdc49ee4afe4bbb26617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= <cem.moreau@gmail.com> Date: Sat, 10 Mar 2018 12:43:45 +0100 Subject: [PATCH] [fix] #1292 Crash on Windows --- app/lib/logger.ts | 6 ++++++ bin/duniter | 25 +++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/lib/logger.ts b/app/lib/logger.ts index b1a5a0e33..0fe2865b8 100644 --- a/app/lib/logger.ts +++ b/app/lib/logger.ts @@ -15,6 +15,7 @@ const moment = require('moment'); const path = require('path'); const winston = require('winston'); +const directory = require('../lib/system/directory'); /*************** * CALLBACK LOGGER @@ -147,6 +148,11 @@ logger.unmute = () => { } } +/** + * Default logging path + */ +logger.addHomeLogs(directory.INSTANCE_HOME) + /** * Convenience function to get logger directly */ diff --git a/bin/duniter b/bin/duniter index 639437438..60946d8e6 100755 --- a/bin/duniter +++ b/bin/duniter @@ -2,27 +2,28 @@ "use strict"; const co = require('co'); -const duniter = require('../index'); -const stack = duniter.statics.autoStack(); +const logger = require("../app/lib/logger").NewLogger(); -return co(function*() { +// Specific errors handling +process.on('uncaughtException', (err) => { + // Dunno why this specific exception is not caught + if (err.code && err.code !== "EADDRNOTAVAIL" && err.code !== "EINVAL" && err.code !== "ENOENT") { + logger.error(err.stack || err.message || err); + process.exit(2); + } +}); - // Specific errors handling - process.on('uncaughtException', (err) => { - // Dunno why this specific exception is not caught - if (err.code !== "EADDRNOTAVAIL" && err.code !== "EINVAL" && err.code !== "ENOENT") { - duniter.statics.logger.error(err); - process.exit(2); - } - }); +return co(function*() { try { + const duniter = require('../index'); + const stack = duniter.statics.autoStack(); yield stack.executeStack(process.argv); // Everything went well, close Duniter quietly. process.exit(); } catch (e) { // If an unhandled error occured - duniter.statics.logger.error(e); + logger.error(e.stack || e.message || e); process.exit(1); } finally { // If we did not succeed to close before, force close with error. -- GitLab