From 074c065262d78f0b3eb769c1cb46eba66f9febac Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 30 Jun 2017 03:24:26 -0700 Subject: [PATCH] node: automatically bind to errors for plugins. --- lib/node/node.js | 13 ++++++------- lib/wallet/plugin.js | 4 ---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/node/node.js b/lib/node/node.js index 73434024..c0a5f520 100644 --- a/lib/node/node.js +++ b/lib/node/node.js @@ -45,9 +45,10 @@ function Node(options) { this.plugins = {}; this.stack = []; - this.spv = false; this.logger = null; this.workers = null; + + this.spv = false; this.chain = null; this.fees = null; this.mempool = null; @@ -212,6 +213,7 @@ Node.prototype.handleOpen = async function handleOpen() { */ Node.prototype.handlePreclose = async function handlePreclose() { + ; }; /** @@ -291,7 +293,6 @@ Node.prototype.use = function use(plugin) { // Reserved names switch (plugin.id) { - case 'logger': case 'chain': case 'fees': case 'mempool': @@ -308,6 +309,9 @@ Node.prototype.use = function use(plugin) { this.stack.push(instance); + if (typeof instance.on === 'function') + instance.on('error', err => this.error(err)); + return instance; }; @@ -333,9 +337,6 @@ Node.prototype.require = function require(name) { assert(typeof name === 'string', 'Plugin name must be a string.'); switch (name) { - case 'logger': - assert(this.logger, 'logger is not loaded.'); - return this.logger; case 'chain': assert(this.chain, 'chain is not loaded.'); return this.chain; @@ -372,8 +373,6 @@ Node.prototype.loadPlugins = function loadPlugins() { return; for (let plugin of plugins) { - assert(plugin); - if (typeof plugin === 'string') plugin = loader(plugin); diff --git a/lib/wallet/plugin.js b/lib/wallet/plugin.js index 9e7ef27b..5adb9bd7 100644 --- a/lib/wallet/plugin.js +++ b/lib/wallet/plugin.js @@ -62,9 +62,5 @@ plugin.init = function init(node) { wdb.rpc.attach(node.rpc); - wdb.on('error', (err) => { - wdb.logger.error(err); - }); - return wdb; };