Skip to content

Commit

Permalink
Plugins: Emit nicer error message when trying to install unknown plugin
Browse files Browse the repository at this point in the history
When installing plugins, we first try the elastic download service for
official plugins, then try maven coordinates, and finally try the
argument as a url. This can lead to confusing error messages about
unknown protocols when eg an official plugin name is mispelled. This
change adds a heuristic for determining if the argument in the final
case is in fact a url that we should try, and gives a simplified error
message in the case it is definitely not a url.

closes elastic#17226
  • Loading branch information
rjernst committed Jun 15, 2016
1 parent fa77d4d commit 6db3231
Showing 1 changed file with 7 additions and 0 deletions.
Expand Up @@ -134,6 +134,9 @@ class InstallPluginCommand extends SettingCommand {
}
}

// protocols allowed for direct url installation
private static final List<String> URL_PROTOCOLS = Arrays.asList("http", "https", "file");

private final OptionSpec<Void> batchOption;
private final OptionSpec<String> arguments;

Expand Down Expand Up @@ -237,6 +240,10 @@ private Path download(Terminal terminal, String pluginId, Path tmpDir) throws Ex
}

// fall back to plain old URL
if (pluginId.contains("://") == false) {
// definitely not a valid url, so assume it is a plugin name
throw new UserError(ExitCodes.USAGE, "Unknown plugin " + pluginId);
}
terminal.println("-> Downloading " + URLDecoder.decode(pluginId, "UTF-8"));
return downloadZip(terminal, pluginId, tmpDir);
}
Expand Down

0 comments on commit 6db3231

Please sign in to comment.