Browse Source

Merge pull request #683 from mrfelton/fix/lnd-error-detail

feat(lnd): show error message if lnd exits
renovate/lint-staged-8.x
JimmyMow 7 years ago
committed by GitHub
parent
commit
097b2fb700
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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

@ -309,12 +309,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

@ -28,6 +28,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