joyent/node-triton#213 commands fail unhelpfully when cliSetupTritonApi returns error

Reviewed by: Trent Mick <trent.mick@joyent.com>
Reviewed by: Sam Gwydir <sam.gwydir@joyent.com>
Approved by: Trent Mick <trent.mick@joyent.com>
This commit is contained in:
Alex Wilson 2017-06-28 13:44:15 -07:00
parent 8493c52be3
commit 9f17d668c9
33 changed files with 38 additions and 0 deletions

View File

@ -9,6 +9,9 @@ Known issues:
- [joyent/node-triton#193] Fix possible CLI crash with `triton ssh ...` if the - [joyent/node-triton#193] Fix possible CLI crash with `triton ssh ...` if the
instance's image doesn't have any tags. instance's image doesn't have any tags.
- [joyent/node-triton#213] commands fail unhelpfully when `cliSetupTritonApi`
returns error (this includes e.g. supplying an incorrect key fingerprint,
which no longer results in a cryptic stack trace and crash)
## 5.2.0 ## 5.2.0

View File

@ -25,6 +25,7 @@ function do_get(subcmd, opts, args, callback) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
callback(setupErr); callback(setupErr);
return;
} }
tritonapi.cloudapi.getAccount(function (err, account) { tritonapi.cloudapi.getAccount(function (err, account) {
if (err) { if (err) {

View File

@ -36,6 +36,7 @@ function do_datacenters(subcmd, opts, args, callback) {
common.cliSetupTritonApi({cli: this}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
callback(setupErr); callback(setupErr);
return;
} }
tritonapi.cloudapi.listDatacenters(function (err, datacenters) { tritonapi.cloudapi.listDatacenters(function (err, datacenters) {
if (err) { if (err) {

View File

@ -49,6 +49,7 @@ function do_create(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
tritonapi.cloudapi.createFirewallRule( tritonapi.cloudapi.createFirewallRule(
createOpts, function (err, fwrule) { createOpts, function (err, fwrule) {

View File

@ -34,6 +34,7 @@ function do_disable(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
vasync.forEachParallel({ vasync.forEachParallel({
inputs: args, inputs: args,

View File

@ -34,6 +34,7 @@ function do_enable(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
vasync.forEachParallel({ vasync.forEachParallel({
inputs: args, inputs: args,

View File

@ -38,6 +38,7 @@ function do_get(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
tritonapi.getFirewallRule(id, function onRule(err, fwrule) { tritonapi.getFirewallRule(id, function onRule(err, fwrule) {
if (err) { if (err) {

View File

@ -57,6 +57,7 @@ function do_instances(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
vasync.parallel({funcs: [ vasync.parallel({funcs: [
function getTheImages(next) { function getTheImages(next) {

View File

@ -39,6 +39,7 @@ function do_list(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
tritonapi.cloudapi.listFirewallRules({}, function onRules(err, rules) { tritonapi.cloudapi.listFirewallRules({}, function onRules(err, rules) {
if (err) { if (err) {

View File

@ -29,6 +29,7 @@ function do_get(subcmd, opts, args, callback) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
callback(setupErr); callback(setupErr);
return;
} }
tritonapi.getImage(args[0], function onRes(err, img) { tritonapi.getImage(args[0], function onRes(err, img) {
if (err) { if (err) {

View File

@ -67,6 +67,7 @@ function do_list(subcmd, opts, args, callback) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
callback(setupErr); callback(setupErr);
return;
} }
tritonapi.listImages(listOpts, function onRes(err, imgs, res) { tritonapi.listImages(listOpts, function onRes(err, imgs, res) {
if (err) { if (err) {

View File

@ -33,6 +33,7 @@ function do_info(subcmd, opts, args, callback) {
common.cliSetupTritonApi({cli: this}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
callback(setupErr); callback(setupErr);
return;
} }
tritonapi.cloudapi.getAccount(cb.bind('account')); i++; tritonapi.cloudapi.getAccount(cb.bind('account')); i++;
tritonapi.cloudapi.listMachines(cb.bind('machines')); i++; tritonapi.cloudapi.listMachines(cb.bind('machines')); i++;

View File

@ -53,6 +53,10 @@ function do_audit(subcmd, opts, args, cb) {
var tritonapi = this.top.tritonapi; var tritonapi = this.top.tritonapi;
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) {
cb(setupErr);
return;
}
if (common.isUUID(arg)) { if (common.isUUID(arg)) {
uuid = arg; uuid = arg;
go1(); go1();

View File

@ -54,6 +54,7 @@ function do_disable_firewall(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
vasync.forEachParallel({ vasync.forEachParallel({
inputs: args, inputs: args,

View File

@ -54,6 +54,7 @@ function do_enable_firewall(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
vasync.forEachParallel({ vasync.forEachParallel({
inputs: args, inputs: args,

View File

@ -44,6 +44,7 @@ function do_list(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
tritonapi.listInstanceFirewallRules({ tritonapi.listInstanceFirewallRules({
id: id id: id

View File

@ -23,6 +23,7 @@ function do_get(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
tritonapi.getInstance(args[0], function (err, inst) { tritonapi.getInstance(args[0], function (err, inst) {
if (inst) { if (inst) {

View File

@ -33,6 +33,7 @@ function do_ip(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
cli.tritonapi.getInstance(args[0], function (err, inst) { cli.tritonapi.getInstance(args[0], function (err, inst) {
if (err) { if (err) {

View File

@ -77,6 +77,7 @@ function do_list(subcmd, opts, args, callback) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
callback(setupErr); callback(setupErr);
return;
} }
vasync.parallel({funcs: [ vasync.parallel({funcs: [
function getTheImages(next) { function getTheImages(next) {

View File

@ -30,6 +30,7 @@ function do_reboot(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
var rebootErrs = []; var rebootErrs = [];

View File

@ -27,6 +27,7 @@ function do_rename(subcmd, opts, args, callback) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
callback(setupErr); callback(setupErr);
return;
} }
tritonapi.renameInstance({ tritonapi.renameInstance({

View File

@ -27,6 +27,7 @@ function do_resize(subcmd, opts, args, callback) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
callback(setupErr); callback(setupErr);
return;
} }
tritonapi.resizeInstance({ tritonapi.resizeInstance({

View File

@ -39,6 +39,7 @@ function do_get(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
cli.tritonapi.getInstanceSnapshot({ cli.tritonapi.getInstanceSnapshot({
id: id, id: id,

View File

@ -43,6 +43,7 @@ function do_list(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
cli.tritonapi.listInstanceSnapshots({ cli.tritonapi.listInstanceSnapshots({
id: machineId id: machineId

View File

@ -33,6 +33,7 @@ function do_delete(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
if (opts.all) { if (opts.all) {
self.top.tritonapi.deleteAllInstanceTags({ self.top.tritonapi.deleteAllInstanceTags({

View File

@ -27,6 +27,7 @@ function do_get(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
self.top.tritonapi.getInstanceTag({ self.top.tritonapi.getInstanceTag({
id: args[0], id: args[0],

View File

@ -26,6 +26,7 @@ function do_list(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
self.top.tritonapi.listInstanceTags( self.top.tritonapi.listInstanceTags(
{id: args[0]}, function (err, tags) { {id: args[0]}, function (err, tags) {

View File

@ -112,6 +112,7 @@ function _doTheAction(action, subcmd, opts, args, callback) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
callback(setupErr); callback(setupErr);
return;
} }
_doOnEachInstance(self, action, command, state, args, opts, callback); _doOnEachInstance(self, action, command, state, args, opts, callback);
}); });

View File

@ -38,6 +38,7 @@ function do_get(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
cli.tritonapi.cloudapi.getKey({ cli.tritonapi.cloudapi.getKey({
// Currently `cloudapi.getUserKey` isn't picky about the // Currently `cloudapi.getUserKey` isn't picky about the

View File

@ -40,6 +40,7 @@ function do_list(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
cli.tritonapi.cloudapi.listKeys({}, function onKeys(err, keys) { cli.tritonapi.cloudapi.listKeys({}, function onKeys(err, keys) {
if (err) { if (err) {

View File

@ -30,6 +30,7 @@ function do_get(subcmd, opts, args, cb) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
cb(setupErr); cb(setupErr);
return;
} }
tritonapi.getNetwork(args[0], function (err, net) { tritonapi.getNetwork(args[0], function (err, net) {
if (err) { if (err) {

View File

@ -29,6 +29,7 @@ function do_get(subcmd, opts, args, callback) {
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
callback(setupErr); callback(setupErr);
return;
} }
tritonapi.getPackage(args[0], function onRes(err, pkg) { tritonapi.getPackage(args[0], function onRes(err, pkg) {
if (err) { if (err) {

View File

@ -36,6 +36,7 @@ function do_services(subcmd, opts, args, callback) {
common.cliSetupTritonApi({cli: this}, function onSetup(setupErr) { common.cliSetupTritonApi({cli: this}, function onSetup(setupErr) {
if (setupErr) { if (setupErr) {
callback(setupErr); callback(setupErr);
return;
} }
tritonapi.cloudapi.listServices(function (err, services) { tritonapi.cloudapi.listServices(function (err, services) {
if (err) { if (err) {