From 441a85cb91d99cf4e79c9cf930f25e538d088c5b Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Fri, 17 Aug 2018 09:00:20 +0200 Subject: [PATCH] feat(lnd): show error message if lnd exists If lnd unexpectedly exists, show the user the last error message reported by lnd in order to help diagnose issues. See #674 --- app/lib/lnd/neutrino.js | 18 ++++++++++++++---- app/lib/zap/controller.js | 4 ++-- test/unit/lnd/neutrino.spec.js | 3 +++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/lib/lnd/neutrino.js b/app/lib/lnd/neutrino.js index fb5caced818..760e9864699 100644 --- a/app/lib/lnd/neutrino.js +++ b/app/lib/lnd/neutrino.js @@ -35,6 +35,7 @@ class Neutrino extends EventEmitter { currentBlockHeight: number lndBlockHeight: number lndCfilterHeight: number + lastError: ?string constructor(lndConfig: LndConfig) { super() @@ -46,6 +47,7 @@ class Neutrino extends EventEmitter { this.currentBlockHeight = 0 this.lndBlockHeight = 0 this.lndCfilterHeight = 0 + this.lastError = null } static incrementIfHigher = (context: any, property: string, newVal: any): boolean => { @@ -91,21 +93,29 @@ class Neutrino extends EventEmitter { this.process = spawn(this.lndConfig.binaryPath, neutrinoArgs) .on('error', error => this.emit(ERROR, error)) .on('close', code => { - this.emit(CLOSE, code) + this.emit(CLOSE, code, this.lastError) this.process = null }) - // Listen for when neutrino prints odata to stderr. + // Listen for when neutrino prints data to stderr. this.process.stderr.pipe(split2()).on('data', line => { if (process.env.NODE_ENV === 'development') { - lndLog[lndLogGetLevel(line)](line) + const level = lndLogGetLevel(line) + lndLog[level](line) + if (level === 'error') { + this.lastError = line.split('[ERR] LTND:')[1] + } } }) // Listen for when neutrino prints data to stdout. this.process.stdout.pipe(split2()).on('data', line => { if (process.env.NODE_ENV === 'development') { - lndLog[lndLogGetLevel(line)](line) + const level = lndLogGetLevel(line) + lndLog[level](line) + if (level === 'error') { + this.lastError = line.split('[ERR] LTND:')[1] + } } // password RPC server listening (wallet unlocker started). diff --git a/app/lib/zap/controller.js b/app/lib/zap/controller.js index 9c1cee80914..19be28ecc70 100644 --- a/app/lib/zap/controller.js +++ b/app/lib/zap/controller.js @@ -312,12 +312,12 @@ class ZapController { }) }) - this.neutrino.on('close', code => { + this.neutrino.on('close', (code, lastError) => { mainLog.info(`Lnd process has shut down (code ${code})`) if (this.is('running') || this.is('connected')) { dialog.showMessageBox({ type: 'error', - message: `Lnd has unexpectadly quit` + message: `Lnd has unexpectadly quit: ${lastError}` }) this.terminate() } diff --git a/test/unit/lnd/neutrino.spec.js b/test/unit/lnd/neutrino.spec.js index c89c348978b..915a00705de 100644 --- a/test/unit/lnd/neutrino.spec.js +++ b/test/unit/lnd/neutrino.spec.js @@ -37,6 +37,9 @@ describe('Neutrino', function() { it('should set the "lndCfilterHeight" property to 0', () => { expect(this.neutrino.lndCfilterHeight).toEqual(0) }) + it('should set the "lastError" property to be null', () => { + expect(this.neutrino.lastError).toEqual(null) + }) }) })