mirror of https://github.com/BTCPrivate/copay.git
improve error handling - print error rather than crash
This commit is contained in:
parent
8d0743a948
commit
cba3487988
26
bin/Copay.js
26
bin/Copay.js
|
@ -1,6 +1,6 @@
|
||||||
var imports = require('soop').imports();
|
var imports = require('soop').imports();
|
||||||
var PublicKeyRing = imports.PublicKeyRing || require('../js/models/core/PublicKeyRing');
|
var PublicKeyRing = imports.PublicKeyRing || require('../js/models/core/PublicKeyRing');
|
||||||
var Wallet = imports.Wallet || require('../js/models/core/Wallet');
|
//var Wallet = imports.Wallet || require('../js/models/core/Wallet');
|
||||||
|
|
||||||
var Copay = function(opts) {
|
var Copay = function(opts) {
|
||||||
this._init(opts);
|
this._init(opts);
|
||||||
|
@ -23,7 +23,7 @@ Copay.prototype._init = function(opts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.publicKeyRing = self.opts.publicKeyRing ? self.opts.publicKeyRing : new PublicKeyRing();
|
self.publicKeyRing = self.opts.publicKeyRing ? self.opts.publicKeyRing : new PublicKeyRing();
|
||||||
self.wallet = self.opts.wallet ? self.opts.wallet : new Wallet();
|
//self.wallet = self.opts.wallet ? self.opts.wallet : new Wallet();
|
||||||
};
|
};
|
||||||
|
|
||||||
Copay.prototype._command = function(command, args, callback) {
|
Copay.prototype._command = function(command, args, callback) {
|
||||||
|
@ -57,9 +57,9 @@ function checkArgs(name, args) {
|
||||||
throw new Error('Invalid arguments');
|
throw new Error('Invalid arguments');
|
||||||
}
|
}
|
||||||
|
|
||||||
Copay.prototype.echo = function(str, callback) {
|
Copay.prototype.echo = function echo(str, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
checkArgs('echo', arguments);
|
checkArgs(arguments.callee.name, arguments);
|
||||||
|
|
||||||
return callback(null, str);
|
return callback(null, str);
|
||||||
};
|
};
|
||||||
|
@ -70,6 +70,7 @@ Copay.prototype.echo.argTypes =
|
||||||
['callback', 'function']
|
['callback', 'function']
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/*
|
||||||
Copay.prototype.getBalance = function(callback) {
|
Copay.prototype.getBalance = function(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
checkArgs('getBalance', arguments);
|
checkArgs('getBalance', arguments);
|
||||||
|
@ -81,10 +82,11 @@ Copay.prototype.getBalance.argTypes =
|
||||||
[
|
[
|
||||||
['callback', 'function']
|
['callback', 'function']
|
||||||
];
|
];
|
||||||
|
*/
|
||||||
|
|
||||||
Copay.prototype.getCommands = function(callback) {
|
Copay.prototype.getCommands = function getCommands(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
checkArgs('getCommands', arguments);
|
checkArgs(arguments.callee.name, arguments);
|
||||||
|
|
||||||
var fs = [];
|
var fs = [];
|
||||||
|
|
||||||
|
@ -102,9 +104,9 @@ Copay.prototype.getCommands.argTypes =
|
||||||
['callback', 'function']
|
['callback', 'function']
|
||||||
];
|
];
|
||||||
|
|
||||||
Copay.prototype.getPublicKeyRingId = function(callback) {
|
Copay.prototype.getPublicKeyRingId = function getPublicKeyRingId(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
checkArgs('getPublicKeyRingId', arguments);
|
checkArgs(arguments.callee.name, arguments);
|
||||||
|
|
||||||
return callback(null, self.publicKeyRing.id);
|
return callback(null, self.publicKeyRing.id);
|
||||||
};
|
};
|
||||||
|
@ -114,5 +116,13 @@ Copay.prototype.getPublicKeyRingId.argTypes =
|
||||||
['callback', 'function']
|
['callback', 'function']
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Copay.prototype.help = function help(callback) {
|
||||||
|
this.getCommands.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
Copay.prototype.help.argTypes =
|
||||||
|
[
|
||||||
|
['callback', 'function']
|
||||||
|
];
|
||||||
|
|
||||||
module.exports = require('soop')(Copay);
|
module.exports = require('soop')(Copay);
|
||||||
|
|
|
@ -19,12 +19,16 @@ var main = function() {
|
||||||
|
|
||||||
var args = commander.args;
|
var args = commander.args;
|
||||||
|
|
||||||
|
try {
|
||||||
copay._command(args[0], args.slice(1), function(err, result) {
|
copay._command(args[0], args.slice(1), function(err, result) {
|
||||||
if (err)
|
if (err)
|
||||||
return console.log("" + err);
|
return console.log("" + err);
|
||||||
|
|
||||||
console.log(JSON.stringify(result, null, 2));
|
console.log(JSON.stringify(result, null, 2));
|
||||||
});
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.log("" + err);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
|
|
Loading…
Reference in New Issue