diff --git a/src/commands/plugins/install.ts b/src/commands/plugins/install.ts index b25b48fd..03d6cf58 100644 --- a/src/commands/plugins/install.ts +++ b/src/commands/plugins/install.ts @@ -55,17 +55,22 @@ e.g. If you have a core plugin that has a 'hello' command, installing a user-ins await this.config.runHook('plugins:preinstall', { plugin: p, }) - if (p.type === 'npm') { - cli.action.start( - `Installing plugin ${chalk.cyan(this.plugins.friendlyName(p.name))}`, - ) - plugin = await this.plugins.install(p.name, { - tag: p.tag, - force: flags.force, - }) - } else { - cli.action.start(`Installing plugin ${chalk.cyan(p.url)}`) - plugin = await this.plugins.install(p.url, {force: flags.force}) + try { + if (p.type === 'npm') { + cli.action.start( + `Installing plugin ${chalk.cyan(this.plugins.friendlyName(p.name))}`, + ) + plugin = await this.plugins.install(p.name, { + tag: p.tag, + force: flags.force, + }) + } else { + cli.action.start(`Installing plugin ${chalk.cyan(p.url)}`) + plugin = await this.plugins.install(p.url, {force: flags.force}) + } + } catch (error) { + cli.action.stop(chalk.bold.red('failed')) + throw error } cli.action.stop(`installed v${plugin.version}`) } diff --git a/src/plugins.ts b/src/plugins.ts index e8273971..6a7efc01 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -55,6 +55,11 @@ export default class Plugins { await this.createPJSON() let plugin const add = force ? ['add', '--force'] : ['add'] + const invalidPluginError = new CLIError('plugin is invalid', { + suggestions: [ + 'Plugin failed to install because it does not appear to be a valid CLI plugin.\nIf you are sure it is, contact the CLI developer noting this error.', + ], + }) if (name.includes(':')) { // url const url = name @@ -63,7 +68,7 @@ export default class Plugins { plugin = await Config.load({devPlugins: false, userPlugins: false, root: path.join(this.config.dataDir, 'node_modules', name), name}) await this.refresh(plugin.root) if (!plugin.valid && !this.config.plugins.find(p => p.name === '@oclif/plugin-legacy')) { - throw new Error('plugin is invalid') + throw invalidPluginError } await this.add({name, url, type: 'user'}) } else { @@ -76,7 +81,7 @@ export default class Plugins { await this.yarn.exec([...add, `${name}@${tag}`], yarnOpts) plugin = await Config.load({devPlugins: false, userPlugins: false, root: path.join(this.config.dataDir, 'node_modules', name), name}) if (!plugin.valid && !this.config.plugins.find(p => p.name === '@oclif/plugin-legacy')) { - throw new Error('plugin is invalid') + throw invalidPluginError } await this.refresh(plugin.root) await this.add({name, tag: range || tag, type: 'user'})