From c2810b626c7407caee775f765286357ea227f12d Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 22 Jun 2017 13:39:47 -0400 Subject: [PATCH] Propagate errors to subscribers with an onDidError callback --- src/filesystem-manager.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/filesystem-manager.js b/src/filesystem-manager.js index 277c7cbfe..47ec98af4 100644 --- a/src/filesystem-manager.js +++ b/src/filesystem-manager.js @@ -113,6 +113,13 @@ class NativeWatcher { return this.emitter.on('did-stop', callback) } + // Private: Register a callback to be invoked with any errors reported from the watcher. + // + // Returns: A {Disposable} to revoke the subscription. + onDidError (callback) { + return this.emitter.on('did-error', callback) + } + // Private: Broadcast an `onShouldDetach` event to prompt any {Watcher} instances bound here to attach to a new // {NativeWatcher} instead. reattachTo (other) { @@ -160,11 +167,7 @@ class NativeWatcher { // // * `err` The native filesystem error. onError (err) { - if (!this.isRunning()) { - return - } - - console.error(err) + this.emitter.emit('did-error', err) } } @@ -232,6 +235,10 @@ class Watcher { }) } + onDidError (callback) { + return this.emitter.on('did-error', callback) + } + attachToNative (native) { this.subs.dispose() this.native = native @@ -251,6 +258,10 @@ class Watcher { formerSub.dispose() } + this.subs.add(native.onDidError(err => { + this.emitter.emit('did-error', err) + })) + this.subs.add(native.onShouldDetach(replacement => { if (replacement !== native) { this.attachToNative(replacement)