From 4bd40f543dc89f0721020e7d0bb3497300d74818 Mon Sep 17 00:00:00 2001 From: Federico Rampazzo Date: Mon, 20 Aug 2018 23:29:59 +0100 Subject: [PATCH] install: Prevent blowing up on audit malformed response (#42) PR-URL: https://github.com/npm/cli/pull/42 Credit: @framp Reviewed-By: @zkat --- lib/install.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/install.js b/lib/install.js index 66f85d80a49a2..e15bc47919100 100644 --- a/lib/install.js +++ b/lib/install.js @@ -766,6 +766,9 @@ Installer.prototype.printInstalled = function (cb) { if (!this.auditSubmission) return return Bluebird.resolve(this.auditSubmission).timeout(10000).catch(() => null) }).then((auditResult) => { + if (auditResult && !auditResult.metadata) { + log.warn('audit', 'Audit result from registry missing metadata. This is probably an issue with the registry.') + } // maybe write audit report w/ hash of pjson & shrinkwrap for later reading by `npm audit` if (npm.config.get('json')) { return this.printInstalledForJSON(diffs, auditResult) @@ -834,7 +837,7 @@ Installer.prototype.printInstalledForHuman = function (diffs, auditResult) { if (removed) actions.push('removed ' + packages(removed)) if (updated) actions.push('updated ' + packages(updated)) if (moved) actions.push('moved ' + packages(moved)) - if (auditResult && auditResult.metadata.totalDependencies) { + if (auditResult && auditResult.metadata && auditResult.metadata.totalDependencies) { actions.push('audited ' + packages(auditResult.metadata.totalDependencies)) } if (actions.length === 0) {