Skip to content

Commit

Permalink
feat(lnd): show error message if lnd exists
Browse files Browse the repository at this point in the history
If lnd unexpectedly exists, show the user the last error message
reported by lnd in order to help diagnose issues.

See LN-Zap#674
  • Loading branch information
mrfelton committed Aug 17, 2018
1 parent b1be3f4 commit 441a85c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
18 changes: 14 additions & 4 deletions app/lib/lnd/neutrino.js
Expand Up @@ -35,6 +35,7 @@ class Neutrino extends EventEmitter {
currentBlockHeight: number
lndBlockHeight: number
lndCfilterHeight: number
lastError: ?string

constructor(lndConfig: LndConfig) {
super()
Expand All @@ -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 => {
Expand Down Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions app/lib/zap/controller.js
Expand Up @@ -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()
}
Expand Down
3 changes: 3 additions & 0 deletions test/unit/lnd/neutrino.spec.js
Expand Up @@ -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)
})
})
})

Expand Down

0 comments on commit 441a85c

Please sign in to comment.