Provide error message when plugin id is missing
Today when executing the install plugin command without a plugin id, we end up throwing an NPE because the plugin id is null yet we just keep going (ultimatley we try to lookup the null plugin id in a set, the direct cause of the NPE). This commit modifies the install command so that a missing plugin id is detected and help is provided to the user. Relates #20660
This commit is contained in:
parent
560fba1b28
commit
a6e33494ab
|
@ -192,6 +192,9 @@ class InstallPluginCommand extends SettingCommand {
|
||||||
|
|
||||||
// pkg private for testing
|
// pkg private for testing
|
||||||
void execute(Terminal terminal, String pluginId, boolean isBatch, Map<String, String> settings) throws Exception {
|
void execute(Terminal terminal, String pluginId, boolean isBatch, Map<String, String> settings) throws Exception {
|
||||||
|
if (pluginId == null) {
|
||||||
|
throw new UserException(ExitCodes.USAGE, "plugin id is required");
|
||||||
|
}
|
||||||
final Environment env = InternalSettingsPreparer.prepareEnvironment(Settings.EMPTY, terminal, settings);
|
final Environment env = InternalSettingsPreparer.prepareEnvironment(Settings.EMPTY, terminal, settings);
|
||||||
// TODO: remove this leniency!! is it needed anymore?
|
// TODO: remove this leniency!! is it needed anymore?
|
||||||
if (Files.exists(env.pluginsFile()) == false) {
|
if (Files.exists(env.pluginsFile()) == false) {
|
||||||
|
|
|
@ -291,6 +291,12 @@ public class InstallPluginCommandTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testMissingPluginId() throws IOException {
|
||||||
|
final Tuple<Path, Environment> env = createEnv(fs, temp);
|
||||||
|
final UserException e = expectThrows(UserException.class, () -> installPlugin(null, env.v1()));
|
||||||
|
assertTrue(e.getMessage(), e.getMessage().contains("plugin id is required"));
|
||||||
|
}
|
||||||
|
|
||||||
public void testSomethingWorks() throws Exception {
|
public void testSomethingWorks() throws Exception {
|
||||||
Tuple<Path, Environment> env = createEnv(fs, temp);
|
Tuple<Path, Environment> env = createEnv(fs, temp);
|
||||||
Path pluginDir = createPluginDir(temp);
|
Path pluginDir = createPluginDir(temp);
|
||||||
|
|
Loading…
Reference in New Issue