diff --git a/CHANGES.md b/CHANGES.md index ea6f9a7..ad3bcf5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,9 @@ ## 4.5.1 (not yet released) -(nothing yet) +- #92 `triton` CLI should summarize `err.body.errors` from CloudAPI + Per , + CloudAPI error response will sometimes have extra error details to show. ## 4.5.0 diff --git a/lib/cli.js b/lib/cli.js index a9cecfa..49a1409 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -400,11 +400,28 @@ function main(argv) { if (code === 'NoCommand') { /* jsl:pass */ } else if (err.message !== undefined) { - console.error('%s%s: error%s: %s', + /* + * If the err has `body.errors` (as some Triton/SDC APIs do per + * // JSSTYLED + * https://github.com/joyent/eng/blob/master/docs/index.md#error-handling + * then append a one-line summary for each error object. + */ + var bodyErrors = ''; + if (err.body && err.body.errors) { + err.body.errors.forEach(function (e) { + bodyErrors += format('\n %s: %s', e.field, e.code); + if (e.message) { + bodyErrors += ': ' + e.message; + } + }); + } + + console.error('%s%s: error%s: %s%s', cli.name, (subcmd ? ' ' + subcmd : ''), (code ? format(' (%s)', code) : ''), - (cli.showErrStack ? err.stack : err.message)); + (cli.showErrStack ? err.stack : err.message), + bodyErrors); // If this is a usage error, attempt to show some usage info. if (['Usage', 'Option'].indexOf(code) !== -1 && subcmd) {