Rename UserError
The top-level class Throwable represents all errors and exceptions in Java. This hierarchy is divided into Error and Exception, the former being serious problems that applications should not try to catch and the latter representing exceptional conditions that an application might want to catch and handle. This commit renames org.elasticsearch.cli.UserError to org.elasticsearch.UserException to make its name consistent with where it falls in this hierarchy. Relates #19254
This commit is contained in:
parent
36b887ee7c
commit
f9d55be1ed
|
@ -25,7 +25,7 @@ import org.elasticsearch.Build;
|
|||
import org.elasticsearch.cli.ExitCodes;
|
||||
import org.elasticsearch.cli.SettingCommand;
|
||||
import org.elasticsearch.cli.Terminal;
|
||||
import org.elasticsearch.cli.UserError;
|
||||
import org.elasticsearch.cli.UserException;
|
||||
import org.elasticsearch.monitor.jvm.JvmInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -73,11 +73,11 @@ class Elasticsearch extends SettingCommand {
|
|||
@Override
|
||||
protected void execute(Terminal terminal, OptionSet options, Map<String, String> settings) throws Exception {
|
||||
if (options.nonOptionArguments().isEmpty() == false) {
|
||||
throw new UserError(ExitCodes.USAGE, "Positional arguments not allowed, found " + options.nonOptionArguments());
|
||||
throw new UserException(ExitCodes.USAGE, "Positional arguments not allowed, found " + options.nonOptionArguments());
|
||||
}
|
||||
if (options.has(versionOption)) {
|
||||
if (options.has(daemonizeOption) || options.has(pidfileOption)) {
|
||||
throw new UserError(ExitCodes.USAGE, "Elasticsearch version option is mutually exclusive with any other option");
|
||||
throw new UserException(ExitCodes.USAGE, "Elasticsearch version option is mutually exclusive with any other option");
|
||||
}
|
||||
terminal.println("Version: " + org.elasticsearch.Version.CURRENT
|
||||
+ ", Build: " + Build.CURRENT.shortHash() + "/" + Build.CURRENT.date()
|
||||
|
|
|
@ -55,7 +55,7 @@ public abstract class Command {
|
|||
printHelp(terminal);
|
||||
terminal.println(Terminal.Verbosity.SILENT, "ERROR: " + e.getMessage());
|
||||
return ExitCodes.USAGE;
|
||||
} catch (UserError e) {
|
||||
} catch (UserException e) {
|
||||
if (e.exitCode == ExitCodes.USAGE) {
|
||||
printHelp(terminal);
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public abstract class Command {
|
|||
if (options.has(silentOption)) {
|
||||
if (options.has(verboseOption)) {
|
||||
// mutually exclusive, we can remove this with jopt-simple 5.0, which natively supports it
|
||||
throw new UserError(ExitCodes.USAGE, "Cannot specify -s and -v together");
|
||||
throw new UserException(ExitCodes.USAGE, "Cannot specify -s and -v together");
|
||||
}
|
||||
terminal.setVerbosity(Terminal.Verbosity.SILENT);
|
||||
} else if (options.has(verboseOption)) {
|
||||
|
@ -110,7 +110,7 @@ public abstract class Command {
|
|||
/**
|
||||
* Executes this command.
|
||||
*
|
||||
* Any runtime user errors (like an input file that does not exist), should throw a {@link UserError}. */
|
||||
* Any runtime user errors (like an input file that does not exist), should throw a {@link UserException}. */
|
||||
protected abstract void execute(Terminal terminal, OptionSet options) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -60,11 +60,11 @@ public class MultiCommand extends Command {
|
|||
}
|
||||
String[] args = arguments.values(options).toArray(new String[0]);
|
||||
if (args.length == 0) {
|
||||
throw new UserError(ExitCodes.USAGE, "Missing command");
|
||||
throw new UserException(ExitCodes.USAGE, "Missing command");
|
||||
}
|
||||
Command subcommand = subcommands.get(args[0]);
|
||||
if (subcommand == null) {
|
||||
throw new UserError(ExitCodes.USAGE, "Unknown command [" + args[0] + "]");
|
||||
throw new UserException(ExitCodes.USAGE, "Unknown command [" + args[0] + "]");
|
||||
}
|
||||
subcommand.mainWithoutErrorHandling(Arrays.copyOfRange(args, 1, args.length), terminal);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public abstract class SettingCommand extends Command {
|
|||
final Map<String, String> settings = new HashMap<>();
|
||||
for (final KeyValuePair kvp : settingOption.values(options)) {
|
||||
if (kvp.value.isEmpty()) {
|
||||
throw new UserError(ExitCodes.USAGE, "Setting [" + kvp.key + "] must not be empty");
|
||||
throw new UserException(ExitCodes.USAGE, "Setting [" + kvp.key + "] must not be empty");
|
||||
}
|
||||
settings.put(kvp.key, kvp.value);
|
||||
}
|
||||
|
|
|
@ -22,13 +22,13 @@ package org.elasticsearch.cli;
|
|||
/**
|
||||
* An exception representing a user fixable problem in {@link Command} usage.
|
||||
*/
|
||||
public class UserError extends Exception {
|
||||
public class UserException extends Exception {
|
||||
|
||||
/** The exist status the cli should use when catching this user error. */
|
||||
public final int exitCode;
|
||||
|
||||
/** Constructs a UserError with an exit status and message to show the user. */
|
||||
public UserError(int exitCode, String msg) {
|
||||
/** Constructs a UserException with an exit status and message to show the user. */
|
||||
public UserException(int exitCode, String msg) {
|
||||
super(msg);
|
||||
this.exitCode = exitCode;
|
||||
}
|
|
@ -29,7 +29,7 @@ import org.elasticsearch.bootstrap.JarHell;
|
|||
import org.elasticsearch.cli.ExitCodes;
|
||||
import org.elasticsearch.cli.SettingCommand;
|
||||
import org.elasticsearch.cli.Terminal;
|
||||
import org.elasticsearch.cli.UserError;
|
||||
import org.elasticsearch.cli.UserException;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.hash.MessageDigests;
|
||||
import org.elasticsearch.common.io.FileSystemUtils;
|
||||
|
@ -188,7 +188,7 @@ class InstallPluginCommand extends SettingCommand {
|
|||
// TODO: in jopt-simple 5.0 we can enforce a min/max number of positional args
|
||||
List<String> args = arguments.values(options);
|
||||
if (args.size() != 1) {
|
||||
throw new UserError(ExitCodes.USAGE, "Must supply a single plugin id argument");
|
||||
throw new UserException(ExitCodes.USAGE, "Must supply a single plugin id argument");
|
||||
}
|
||||
String pluginId = args.get(0);
|
||||
boolean isBatch = options.has(batchOption) || System.console() == null;
|
||||
|
@ -250,7 +250,7 @@ class InstallPluginCommand extends SettingCommand {
|
|||
if (plugins.isEmpty() == false) {
|
||||
msg += ", did you mean " + (plugins.size() == 1 ? "[" + plugins.get(0) + "]": "any of " + plugins.toString()) + "?";
|
||||
}
|
||||
throw new UserError(ExitCodes.USAGE, msg);
|
||||
throw new UserException(ExitCodes.USAGE, msg);
|
||||
}
|
||||
terminal.println("-> Downloading " + URLDecoder.decode(pluginId, "UTF-8"));
|
||||
return downloadZip(terminal, pluginId, tmpDir);
|
||||
|
@ -328,20 +328,20 @@ class InstallPluginCommand extends SettingCommand {
|
|||
BufferedReader checksumReader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
expectedChecksum = checksumReader.readLine();
|
||||
if (checksumReader.readLine() != null) {
|
||||
throw new UserError(ExitCodes.IO_ERROR, "Invalid checksum file at " + checksumUrl);
|
||||
throw new UserException(ExitCodes.IO_ERROR, "Invalid checksum file at " + checksumUrl);
|
||||
}
|
||||
}
|
||||
|
||||
byte[] zipbytes = Files.readAllBytes(zip);
|
||||
String gotChecksum = MessageDigests.toHexString(MessageDigests.sha1().digest(zipbytes));
|
||||
if (expectedChecksum.equals(gotChecksum) == false) {
|
||||
throw new UserError(ExitCodes.IO_ERROR, "SHA1 mismatch, expected " + expectedChecksum + " but got " + gotChecksum);
|
||||
throw new UserException(ExitCodes.IO_ERROR, "SHA1 mismatch, expected " + expectedChecksum + " but got " + gotChecksum);
|
||||
}
|
||||
|
||||
return zip;
|
||||
}
|
||||
|
||||
private Path unzip(Path zip, Path pluginsDir) throws IOException, UserError {
|
||||
private Path unzip(Path zip, Path pluginsDir) throws IOException, UserException {
|
||||
// unzip plugin to a staging temp dir
|
||||
|
||||
final Path target = stagingDirectory(pluginsDir);
|
||||
|
@ -386,7 +386,7 @@ class InstallPluginCommand extends SettingCommand {
|
|||
Files.delete(zip);
|
||||
if (hasEsDir == false) {
|
||||
IOUtils.rm(target);
|
||||
throw new UserError(ExitCodes.DATA_ERROR, "`elasticsearch` directory is missing in the plugin zip");
|
||||
throw new UserException(ExitCodes.DATA_ERROR, "`elasticsearch` directory is missing in the plugin zip");
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ class InstallPluginCommand extends SettingCommand {
|
|||
// don't let luser install plugin as a module...
|
||||
// they might be unavoidably in maven central and are packaged up the same way)
|
||||
if (MODULES.contains(info.getName())) {
|
||||
throw new UserError(ExitCodes.USAGE, "plugin '" + info.getName() + "' cannot be installed like this, it is a system module");
|
||||
throw new UserException(ExitCodes.USAGE, "plugin '" + info.getName() + "' cannot be installed like this, it is a system module");
|
||||
}
|
||||
|
||||
// check for jar hell before any copying
|
||||
|
@ -475,7 +475,7 @@ class InstallPluginCommand extends SettingCommand {
|
|||
|
||||
final Path destination = env.pluginsFile().resolve(info.getName());
|
||||
if (Files.exists(destination)) {
|
||||
throw new UserError(
|
||||
throw new UserException(
|
||||
ExitCodes.USAGE,
|
||||
"plugin directory " + destination.toAbsolutePath() +
|
||||
" already exists. To update the plugin, uninstall it first using 'remove " + info.getName() + "' command");
|
||||
|
@ -520,7 +520,7 @@ class InstallPluginCommand extends SettingCommand {
|
|||
/** Copies the files from {@code tmpBinDir} into {@code destBinDir}, along with permissions from dest dirs parent. */
|
||||
private void installBin(PluginInfo info, Path tmpBinDir, Path destBinDir) throws Exception {
|
||||
if (Files.isDirectory(tmpBinDir) == false) {
|
||||
throw new UserError(ExitCodes.IO_ERROR, "bin in plugin " + info.getName() + " is not a directory");
|
||||
throw new UserException(ExitCodes.IO_ERROR, "bin in plugin " + info.getName() + " is not a directory");
|
||||
}
|
||||
Files.createDirectory(destBinDir);
|
||||
setFileAttributes(destBinDir, DIR_AND_EXECUTABLE_PERMS);
|
||||
|
@ -528,7 +528,7 @@ class InstallPluginCommand extends SettingCommand {
|
|||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(tmpBinDir)) {
|
||||
for (Path srcFile : stream) {
|
||||
if (Files.isDirectory(srcFile)) {
|
||||
throw new UserError(
|
||||
throw new UserException(
|
||||
ExitCodes.DATA_ERROR,
|
||||
"Directories not allowed in bin dir for plugin " + info.getName() + ", found " + srcFile.getFileName());
|
||||
}
|
||||
|
@ -547,7 +547,7 @@ class InstallPluginCommand extends SettingCommand {
|
|||
*/
|
||||
private void installConfig(PluginInfo info, Path tmpConfigDir, Path destConfigDir) throws Exception {
|
||||
if (Files.isDirectory(tmpConfigDir) == false) {
|
||||
throw new UserError(ExitCodes.IO_ERROR, "config in plugin " + info.getName() + " is not a directory");
|
||||
throw new UserException(ExitCodes.IO_ERROR, "config in plugin " + info.getName() + " is not a directory");
|
||||
}
|
||||
|
||||
Files.createDirectories(destConfigDir);
|
||||
|
@ -563,7 +563,7 @@ class InstallPluginCommand extends SettingCommand {
|
|||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(tmpConfigDir)) {
|
||||
for (Path srcFile : stream) {
|
||||
if (Files.isDirectory(srcFile)) {
|
||||
throw new UserError(ExitCodes.DATA_ERROR, "Directories not allowed in config dir for plugin " + info.getName());
|
||||
throw new UserException(ExitCodes.DATA_ERROR, "Directories not allowed in config dir for plugin " + info.getName());
|
||||
}
|
||||
|
||||
Path destFile = destConfigDir.resolve(tmpConfigDir.relativize(srcFile));
|
||||
|
|
|
@ -29,10 +29,9 @@ import java.util.Map;
|
|||
import joptsimple.OptionSet;
|
||||
import joptsimple.OptionSpec;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.cli.Command;
|
||||
import org.elasticsearch.cli.ExitCodes;
|
||||
import org.elasticsearch.cli.SettingCommand;
|
||||
import org.elasticsearch.cli.UserError;
|
||||
import org.elasticsearch.cli.UserException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.cli.Terminal;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -58,7 +57,7 @@ class RemovePluginCommand extends SettingCommand {
|
|||
// TODO: in jopt-simple 5.0 we can enforce a min/max number of positional args
|
||||
List<String> args = arguments.values(options);
|
||||
if (args.size() != 1) {
|
||||
throw new UserError(ExitCodes.USAGE, "Must supply a single plugin id argument");
|
||||
throw new UserException(ExitCodes.USAGE, "Must supply a single plugin id argument");
|
||||
}
|
||||
execute(terminal, args.get(0), settings);
|
||||
}
|
||||
|
@ -71,7 +70,7 @@ class RemovePluginCommand extends SettingCommand {
|
|||
|
||||
Path pluginDir = env.pluginsFile().resolve(pluginName);
|
||||
if (Files.exists(pluginDir) == false) {
|
||||
throw new UserError(ExitCodes.USAGE, "plugin " + pluginName + " not found; run 'elasticsearch-plugin list' to get list of installed plugins");
|
||||
throw new UserException(ExitCodes.USAGE, "plugin " + pluginName + " not found; run 'elasticsearch-plugin list' to get list of installed plugins");
|
||||
}
|
||||
|
||||
List<Path> pluginPaths = new ArrayList<>();
|
||||
|
@ -79,7 +78,7 @@ class RemovePluginCommand extends SettingCommand {
|
|||
Path pluginBinDir = env.binFile().resolve(pluginName);
|
||||
if (Files.exists(pluginBinDir)) {
|
||||
if (Files.isDirectory(pluginBinDir) == false) {
|
||||
throw new UserError(ExitCodes.IO_ERROR, "Bin dir for " + pluginName + " is not a directory");
|
||||
throw new UserException(ExitCodes.IO_ERROR, "Bin dir for " + pluginName + " is not a directory");
|
||||
}
|
||||
pluginPaths.add(pluginBinDir);
|
||||
terminal.println(VERBOSE, "Removing: " + pluginBinDir);
|
||||
|
|
|
@ -30,7 +30,7 @@ public class CommandTests extends ESTestCase {
|
|||
}
|
||||
@Override
|
||||
protected void execute(Terminal terminal, OptionSet options) throws Exception {
|
||||
throw new UserError(ExitCodes.DATA_ERROR, "Bad input");
|
||||
throw new UserException(ExitCodes.DATA_ERROR, "Bad input");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class CommandTests extends ESTestCase {
|
|||
}
|
||||
@Override
|
||||
protected void execute(Terminal terminal, OptionSet options) throws Exception {
|
||||
throw new UserError(ExitCodes.USAGE, "something was no good");
|
||||
throw new UserException(ExitCodes.USAGE, "something was no good");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class CommandTests extends ESTestCase {
|
|||
MockTerminal terminal = new MockTerminal();
|
||||
NoopCommand command = new NoopCommand();
|
||||
String[] args = {"-v", "-s"};
|
||||
UserError e = expectThrows(UserError.class, () -> {
|
||||
UserException e = expectThrows(UserException.class, () -> {
|
||||
command.mainWithoutErrorHandling(args, terminal);
|
||||
});
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("Cannot specify -s and -v together"));
|
||||
|
|
|
@ -61,7 +61,7 @@ public class MultiCommandTests extends CommandTestCase {
|
|||
|
||||
public void testUnknownCommand() throws Exception {
|
||||
multiCommand.subcommands.put("something", new DummySubCommand());
|
||||
UserError e = expectThrows(UserError.class, () -> {
|
||||
UserException e = expectThrows(UserException.class, () -> {
|
||||
execute("somethingelse");
|
||||
});
|
||||
assertEquals(ExitCodes.USAGE, e.exitCode);
|
||||
|
@ -70,7 +70,7 @@ public class MultiCommandTests extends CommandTestCase {
|
|||
|
||||
public void testMissingCommand() throws Exception {
|
||||
multiCommand.subcommands.put("command1", new DummySubCommand());
|
||||
UserError e = expectThrows(UserError.class, () -> {
|
||||
UserException e = expectThrows(UserException.class, () -> {
|
||||
execute();
|
||||
});
|
||||
assertEquals(ExitCodes.USAGE, e.exitCode);
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.lucene.util.LuceneTestCase;
|
|||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cli.MockTerminal;
|
||||
import org.elasticsearch.cli.Terminal;
|
||||
import org.elasticsearch.cli.UserError;
|
||||
import org.elasticsearch.cli.UserException;
|
||||
import org.elasticsearch.common.SuppressForbidden;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
|
@ -320,7 +320,7 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|||
|
||||
public void testUnknownPlugin() throws Exception {
|
||||
Tuple<Path, Environment> env = createEnv(fs, temp);
|
||||
UserError e = expectThrows(UserError.class, () -> installPlugin("foo", env.v1()));
|
||||
UserException e = expectThrows(UserException.class, () -> installPlugin("foo", env.v1()));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("Unknown plugin foo"));
|
||||
}
|
||||
|
||||
|
@ -350,7 +350,7 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|||
Tuple<Path, Environment> env = createEnv(fs, temp);
|
||||
Path pluginDir = createPluginDir(temp);
|
||||
String pluginZip = createPlugin("lang-groovy", pluginDir);
|
||||
UserError e = expectThrows(UserError.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("is a system module"));
|
||||
assertInstallCleaned(env.v2());
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|||
Path pluginDir = createPluginDir(temp);
|
||||
String pluginZip = createPlugin("fake", pluginDir);
|
||||
installPlugin(pluginZip, env.v1());
|
||||
UserError e = expectThrows(UserError.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("already exists"));
|
||||
assertInstallCleaned(env.v2());
|
||||
}
|
||||
|
@ -407,7 +407,7 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|||
Path binDir = pluginDir.resolve("bin");
|
||||
Files.createFile(binDir);
|
||||
String pluginZip = createPlugin("fake", pluginDir);
|
||||
UserError e = expectThrows(UserError.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("not a directory"));
|
||||
assertInstallCleaned(env.v2());
|
||||
}
|
||||
|
@ -419,7 +419,7 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|||
Files.createDirectories(dirInBinDir);
|
||||
Files.createFile(dirInBinDir.resolve("somescript"));
|
||||
String pluginZip = createPlugin("fake", pluginDir);
|
||||
UserError e = expectThrows(UserError.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("Directories not allowed in bin dir for plugin"));
|
||||
assertInstallCleaned(env.v2());
|
||||
}
|
||||
|
@ -490,7 +490,7 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|||
Path configDir = pluginDir.resolve("config");
|
||||
Files.createFile(configDir);
|
||||
String pluginZip = createPlugin("fake", pluginDir);
|
||||
UserError e = expectThrows(UserError.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("not a directory"));
|
||||
assertInstallCleaned(env.v2());
|
||||
}
|
||||
|
@ -502,7 +502,7 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|||
Files.createDirectories(dirInConfigDir);
|
||||
Files.createFile(dirInConfigDir.resolve("myconfig.yml"));
|
||||
String pluginZip = createPlugin("fake", pluginDir);
|
||||
UserError e = expectThrows(UserError.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("Directories not allowed in config dir for plugin"));
|
||||
assertInstallCleaned(env.v2());
|
||||
}
|
||||
|
@ -534,7 +534,7 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|||
Path pluginDir = createPluginDir(temp);
|
||||
Files.createFile(pluginDir.resolve(PluginInfo.ES_PLUGIN_PROPERTIES));
|
||||
String pluginZip = writeZip(pluginDir, null);
|
||||
UserError e = expectThrows(UserError.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("`elasticsearch` directory is missing in the plugin zip"));
|
||||
assertInstallCleaned(env.v2());
|
||||
}
|
||||
|
@ -580,16 +580,16 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|||
|
||||
public void testInstallMisspelledOfficialPlugins() throws Exception {
|
||||
Tuple<Path, Environment> env = createEnv(fs, temp);
|
||||
UserError e = expectThrows(UserError.class, () -> installPlugin("xpack", env.v1()));
|
||||
UserException e = expectThrows(UserException.class, () -> installPlugin("xpack", env.v1()));
|
||||
assertThat(e.getMessage(), containsString("Unknown plugin xpack, did you mean [x-pack]?"));
|
||||
|
||||
e = expectThrows(UserError.class, () -> installPlugin("analysis-smartnc", env.v1()));
|
||||
e = expectThrows(UserException.class, () -> installPlugin("analysis-smartnc", env.v1()));
|
||||
assertThat(e.getMessage(), containsString("Unknown plugin analysis-smartnc, did you mean [analysis-smartcn]?"));
|
||||
|
||||
e = expectThrows(UserError.class, () -> installPlugin("repository", env.v1()));
|
||||
e = expectThrows(UserException.class, () -> installPlugin("repository", env.v1()));
|
||||
assertThat(e.getMessage(), containsString("Unknown plugin repository, did you mean any of [repository-s3, repository-gcs]?"));
|
||||
|
||||
e = expectThrows(UserError.class, () -> installPlugin("unknown_plugin", env.v1()));
|
||||
e = expectThrows(UserException.class, () -> installPlugin("unknown_plugin", env.v1()));
|
||||
assertThat(e.getMessage(), containsString("Unknown plugin unknown_plugin"));
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.elasticsearch.cli.UserError;
|
||||
import org.elasticsearch.cli.UserException;
|
||||
import org.elasticsearch.cli.MockTerminal;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
|
@ -72,7 +72,7 @@ public class RemovePluginCommandTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testMissing() throws Exception {
|
||||
UserError e = expectThrows(UserError.class, () -> removePlugin("dne", home));
|
||||
UserException e = expectThrows(UserException.class, () -> removePlugin("dne", home));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("plugin dne not found"));
|
||||
assertRemoveCleaned(env);
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ public class RemovePluginCommandTests extends ESTestCase {
|
|||
|
||||
public void testBinNotDir() throws Exception {
|
||||
Files.createDirectories(env.pluginsFile().resolve("elasticsearch"));
|
||||
UserError e = expectThrows(UserError.class, () -> removePlugin("elasticsearch", home));
|
||||
UserException e = expectThrows(UserException.class, () -> removePlugin("elasticsearch", home));
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("not a directory"));
|
||||
assertTrue(Files.exists(env.pluginsFile().resolve("elasticsearch"))); // did not remove
|
||||
assertTrue(Files.exists(env.binFile().resolve("elasticsearch")));
|
||||
|
|
Loading…
Reference in New Issue