From 4ed1a0fd7af7bc6daf2022c7b073e8ac0c7f2084 Mon Sep 17 00:00:00 2001 From: Robert Martin-Legene <robert@nic.ar> Date: Fri, 30 Aug 2019 00:28:39 -0300 Subject: [PATCH] Better error handling + new startup script --- bin/libbfa.js | 11 ++++++++--- bin/monitor.js | 21 +++++++++++++++++---- bin/singlestart.sh | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/bin/libbfa.js b/bin/libbfa.js index bf0b61b..6cdd2e9 100644 --- a/bin/libbfa.js +++ b/bin/libbfa.js @@ -96,11 +96,16 @@ module.exports = class Libbfa body: body, callback: function RPCresponse( err, obj ) { + var r; + var e; if ( err ) - throw new Error( err ); + e = err; + else if ( obj.body.error && obj.body.error.code && obj.body.error.message ) - throw new Error( 'Error ' + obj.body.error.code + ": "+ obj.body.error.message ); - callback(obj.body.result); + e = 'Error ' + obj.body.error.code + ": "+ obj.body.error.message; + else + r = obj.body.result; + callback(e, r); } }); }; diff --git a/bin/monitor.js b/bin/monitor.js index 0e84360..4414f05 100755 --- a/bin/monitor.js +++ b/bin/monitor.js @@ -120,13 +120,15 @@ function parsenode( node ) return n; } -function gotAdminPeers( nodelist ) +function gotAdminPeers( err, nodelist ) { var nowpeers = []; var peerscache = readPeersCache(); var newoutpeers = []; var currentnodes = []; + if ( err ) + return; // The nodelist also contains peers which are not yet validated // if they even belong to this network. Parsenode returns an // object or nothing, based on our criteria @@ -208,8 +210,9 @@ function mayseal() // Get a list of clique.getSigners, so we can see if we are // in the list of authorized sealers. web3.bfa.clique.getSigners( - function gotListOfSealers(x) + function gotListOfSealers(e,x) { + if (e) return; var lcsealers = x.map( name => name.toLowerCase() ); var isSigner = (lcsealers.indexOf(me) > -1); if ( isSigner ) @@ -245,8 +248,9 @@ function unlock() return; var unlockedsomething = false; web3.bfa.personal.listWallets( - function pushone(x) + function pushone(e,x) { + if (e) return; var i = x.length; var wallets = new Array(); while ( i-- > 0 ) @@ -302,7 +306,16 @@ function unlock() function timer() { if ( netid == 0 ) - web3.eth.net.getId().then( x => {netid = x} ); + { + web3.eth.net.getId() + .then( x => { + netid = x; + } ) + .catch( err => { + console.log("monitor.js non-fatal: "+err) + }); + return; + } peerlist(); mayseal(); unlock(); diff --git a/bin/singlestart.sh b/bin/singlestart.sh index a0dda31..b6f97e8 100755 --- a/bin/singlestart.sh +++ b/bin/singlestart.sh @@ -48,7 +48,7 @@ unset LOGDIR LOGPIPE PIDLIST echo "*** Setting up logging." # Clean up logging -LOGDIR=$( mktemp --directory ) +LOGDIR=$( mktemp -d ) trap "rm -f ${LOGDIR}" EXIT LOGPIPE=${LOGDIR}/logpipe mknod ${LOGPIPE} p -- GitLab