Browse Source

feat(lnd): show error message if lnd exits

If lnd unexpectedly exits, show the user the last error message
reported by lnd in order to help diagnose issues.

See #674
renovate/lint-staged-8.x
Tom Kirkpatrick 6 years ago
parent
commit
1b4de6cb0c
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 18
      app/lib/lnd/neutrino.js
  2. 4
      app/lib/zap/controller.js
  3. 3
      test/unit/lnd/neutrino.spec.js

18
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).

4
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()
}

3
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)
})
})
})

Loading…
Cancel
Save