diff --git a/src/cli/commands/info.js b/src/cli/commands/info.js index 4f8555de6a..ea59d1ed5e 100644 --- a/src/cli/commands/info.js +++ b/src/cli/commands/info.js @@ -5,6 +5,7 @@ import type Config from '../../config.js'; import NpmRegistry from '../../registries/npm-registry.js'; import parsePackageName from '../../util/parse-package-name.js'; const semver = require('semver'); +const invariant = require('invariant'); function clean(object: any): any { if (Array.isArray(object)) { @@ -60,11 +61,14 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg const packageInput = NpmRegistry.escapeName(packageName); const {name, version} = parsePackageName(packageInput); - let result = await config.registries.npm.request(name, {unfiltered: true}); - if (!result) { + let result; + try { + result = await config.registries.npm.request(name, {unfiltered: true}); + } catch (e) { reporter.error(reporter.lang('infoFail')); return; } + invariant(result, 'result must not be empty'); result = clean(result);