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 elastic/elasticsearch#2701

Original commit: elastic/x-pack-elasticsearch@589e159ec0
This commit is contained in:
Jason Tedor 2016-07-04 19:22:46 -04:00 committed by GitHub
parent 8cc49b5b30
commit f1670a3845
14 changed files with 70 additions and 78 deletions

View File

@ -10,7 +10,7 @@ import joptsimple.OptionSpec;
import org.elasticsearch.cli.Command;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.cli.UserError;
import org.elasticsearch.cli.UserException;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.io.PathUtils;
@ -54,9 +54,9 @@ public class KeyPairGeneratorTool extends Command {
Path publicKeyPath = parsePath(publicKeyPathOption.value(options));
Path privateKeyPath = parsePath(privateKeyPathOption.value(options));
if (Files.exists(privateKeyPath)) {
throw new UserError(ExitCodes.USAGE, privateKeyPath + " already exists");
throw new UserException(ExitCodes.USAGE, privateKeyPath + " already exists");
} else if (Files.exists(publicKeyPath)) {
throw new UserError(ExitCodes.USAGE, publicKeyPath + " already exists");
throw new UserException(ExitCodes.USAGE, publicKeyPath + " already exists");
}
SecureRandom random = new SecureRandom();

View File

@ -12,7 +12,7 @@ import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.elasticsearch.cli.Command;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.UserError;
import org.elasticsearch.cli.UserException;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.io.PathUtils;
@ -62,9 +62,9 @@ public class LicenseGeneratorTool extends Command {
Path publicKeyPath = parsePath(publicKeyPathOption.value(options));
Path privateKeyPath = parsePath(privateKeyPathOption.value(options));
if (Files.exists(privateKeyPath) == false) {
throw new UserError(ExitCodes.USAGE, privateKeyPath + " does not exist");
throw new UserException(ExitCodes.USAGE, privateKeyPath + " does not exist");
} else if (Files.exists(publicKeyPath) == false) {
throw new UserError(ExitCodes.USAGE, publicKeyPath + " does not exist");
throw new UserException(ExitCodes.USAGE, publicKeyPath + " does not exist");
}
final License licenseSpec;
@ -73,11 +73,11 @@ public class LicenseGeneratorTool extends Command {
} else if (options.has(licenseFileOption)) {
Path licenseSpecPath = parsePath(licenseFileOption.value(options));
if (Files.exists(licenseSpecPath) == false) {
throw new UserError(ExitCodes.USAGE, licenseSpecPath + " does not exist");
throw new UserException(ExitCodes.USAGE, licenseSpecPath + " does not exist");
}
licenseSpec = License.fromSource(Files.readAllBytes(licenseSpecPath));
} else {
throw new UserError(ExitCodes.USAGE, "Must specify either --license or --licenseFile");
throw new UserException(ExitCodes.USAGE, "Must specify either --license or --licenseFile");
}
// sign

View File

@ -12,7 +12,7 @@ import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.elasticsearch.cli.Command;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.UserError;
import org.elasticsearch.cli.UserException;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.io.PathUtils;
@ -49,7 +49,7 @@ public class LicenseVerificationTool extends Command {
protected void execute(Terminal terminal, OptionSet options) throws Exception {
Path publicKeyPath = parsePath(publicKeyPathOption.value(options));
if (Files.exists(publicKeyPath) == false) {
throw new UserError(ExitCodes.USAGE, publicKeyPath + " does not exist");
throw new UserException(ExitCodes.USAGE, publicKeyPath + " does not exist");
}
final License licenseSpec;
@ -58,16 +58,16 @@ public class LicenseVerificationTool extends Command {
} else if (options.has(licenseFileOption)) {
Path licenseSpecPath = parsePath(licenseFileOption.value(options));
if (Files.exists(licenseSpecPath) == false) {
throw new UserError(ExitCodes.USAGE, licenseSpecPath + " does not exist");
throw new UserException(ExitCodes.USAGE, licenseSpecPath + " does not exist");
}
licenseSpec = License.fromSource(Files.readAllBytes(licenseSpecPath));
} else {
throw new UserError(ExitCodes.USAGE, "Must specify either --license or --licenseFile");
throw new UserException(ExitCodes.USAGE, "Must specify either --license or --licenseFile");
}
// verify
if (LicenseVerifier.verifyLicense(licenseSpec, Files.readAllBytes(publicKeyPath)) == false) {
throw new UserError(ExitCodes.DATA_ERROR, "Invalid License!");
throw new UserException(ExitCodes.DATA_ERROR, "Invalid License!");
}
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.startObject();

View File

@ -11,9 +11,7 @@ import java.nio.file.Path;
import org.elasticsearch.cli.Command;
import org.elasticsearch.cli.CommandTestCase;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.UserError;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.cli.UserException;
import static org.hamcrest.CoreMatchers.containsString;
@ -27,12 +25,12 @@ public class KeyPairGenerationToolTests extends CommandTestCase {
public void testMissingKeyPaths() throws Exception {
Path exists = createTempFile("", "existing");
Path dne = createTempDir().resolve("dne");
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
execute("--publicKeyPath", exists.toString(), "--privateKeyPath", dne.toString());
});
assertThat(e.getMessage(), containsString("existing"));
assertEquals(ExitCodes.USAGE, e.exitCode);
e = expectThrows(UserError.class, () -> {
e = expectThrows(UserException.class, () -> {
execute("--publicKeyPath", dne.toString(), "--privateKeyPath", exists.toString());
});
assertThat(e.getMessage(), containsString("existing"));

View File

@ -12,12 +12,9 @@ import java.nio.file.Path;
import org.elasticsearch.cli.Command;
import org.elasticsearch.cli.CommandTestCase;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.UserError;
import org.elasticsearch.cli.MockTerminal;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.cli.UserException;
import org.elasticsearch.license.core.License;
import org.elasticsearch.license.licensor.TestUtils;
import org.elasticsearch.test.ESTestCase;
import org.junit.Before;
public class LicenseGenerationToolTests extends CommandTestCase {
@ -38,14 +35,14 @@ public class LicenseGenerationToolTests extends CommandTestCase {
public void testMissingKeyPaths() throws Exception {
Path pub = createTempDir().resolve("pub");
Path pri = createTempDir().resolve("pri");
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
execute("--publicKeyPath", pub.toString(), "--privateKeyPath", pri.toString());
});
assertTrue(e.getMessage(), e.getMessage().contains("pri does not exist"));
assertEquals(ExitCodes.USAGE, e.exitCode);
Files.createFile(pri);
e = expectThrows(UserError.class, () -> {
e = expectThrows(UserException.class, () -> {
execute("--publicKeyPath", pub.toString(), "--privateKeyPath", pri.toString());
});
assertTrue(e.getMessage(), e.getMessage().contains("pub does not exist"));
@ -53,7 +50,7 @@ public class LicenseGenerationToolTests extends CommandTestCase {
}
public void testMissingLicenseSpec() throws Exception {
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
execute("--publicKeyPath", pubKeyPath.toString(), "--privateKeyPath", priKeyPath.toString());
});
assertTrue(e.getMessage(), e.getMessage().contains("Must specify either --license or --licenseFile"));

View File

@ -12,7 +12,7 @@ import java.nio.file.Path;
import org.elasticsearch.cli.Command;
import org.elasticsearch.cli.CommandTestCase;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.UserError;
import org.elasticsearch.cli.UserException;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.license.core.License;
import org.elasticsearch.license.licensor.TestUtils;
@ -36,7 +36,7 @@ public class LicenseVerificationToolTests extends CommandTestCase {
public void testMissingKeyPath() throws Exception {
Path pub = createTempDir().resolve("pub");
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
execute("--publicKeyPath", pub.toString());
});
assertTrue(e.getMessage(), e.getMessage().contains("pub does not exist"));
@ -44,7 +44,7 @@ public class LicenseVerificationToolTests extends CommandTestCase {
}
public void testMissingLicenseSpec() throws Exception {
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
execute("--publicKeyPath", pubKeyPath.toString());
});
assertTrue(e.getMessage(), e.getMessage().contains("Must specify either --license or --licenseFile"));
@ -56,7 +56,7 @@ public class LicenseVerificationToolTests extends CommandTestCase {
License tamperedLicense = License.builder()
.fromLicenseSpec(signedLicense, signedLicense.signature())
.expiryDate(signedLicense.expiryDate() + randomIntBetween(1, 1000)).build();
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
execute("--publicKeyPath", pubKeyPath.toString(),
"--license", TestUtils.dumpLicense(tamperedLicense));
});

View File

@ -11,7 +11,7 @@ import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.MultiCommand;
import org.elasticsearch.cli.SettingCommand;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.cli.UserError;
import org.elasticsearch.cli.UserException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.set.Sets;
@ -88,7 +88,7 @@ public class UsersTool extends MultiCommand {
String username = parseUsername(arguments.values(options));
Validation.Error validationError = Users.validateUsername(username);
if (validationError != null) {
throw new UserError(ExitCodes.DATA_ERROR, "Invalid username [" + username + "]... " + validationError);
throw new UserException(ExitCodes.DATA_ERROR, "Invalid username [" + username + "]... " + validationError);
}
char[] password = parsePassword(terminal, passwordOption.value(options));
@ -102,7 +102,7 @@ public class UsersTool extends MultiCommand {
Map<String, char[]> users = new HashMap<>(FileUserPasswdStore.parseFile(passwordFile, null));
if (users.containsKey(username)) {
throw new UserError(ExitCodes.CODE_ERROR, "User [" + username + "] already exists");
throw new UserException(ExitCodes.CODE_ERROR, "User [" + username + "] already exists");
}
Hasher hasher = Hasher.BCRYPT;
users.put(username, hasher.hash(new SecuredString(password)));
@ -149,7 +149,7 @@ public class UsersTool extends MultiCommand {
Map<String, char[]> users = new HashMap<>(FileUserPasswdStore.parseFile(passwordFile, null));
if (users.containsKey(username) == false) {
throw new UserError(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
throw new UserException(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
}
if (Files.exists(passwordFile)) {
char[] passwd = users.remove(username);
@ -205,7 +205,7 @@ public class UsersTool extends MultiCommand {
FileAttributesChecker attributesChecker = new FileAttributesChecker(file);
Map<String, char[]> users = new HashMap<>(FileUserPasswdStore.parseFile(file, null));
if (users.containsKey(username) == false) {
throw new UserError(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
throw new UserException(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
}
users.put(username, Hasher.BCRYPT.hash(new SecuredString(password)));
FileUserPasswdStore.writeFile(users, file);
@ -261,7 +261,7 @@ public class UsersTool extends MultiCommand {
Map<String, char[]> usersMap = FileUserPasswdStore.parseFile(usersFile, null);
if (!usersMap.containsKey(username)) {
throw new UserError(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
throw new UserException(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
}
Map<String, String[]> userRoles = FileUserRolesStore.parseFile(rolesFile, null);
@ -325,7 +325,7 @@ public class UsersTool extends MultiCommand {
if (username != null) {
if (!users.contains(username)) {
throw new UserError(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
throw new UserException(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
}
if (userRoles.containsKey(username)) {
@ -394,38 +394,38 @@ public class UsersTool extends MultiCommand {
}
// pkg private for testing
static String parseUsername(List<String> args) throws UserError {
static String parseUsername(List<String> args) throws UserException {
if (args.isEmpty()) {
throw new UserError(ExitCodes.USAGE, "Missing username argument");
throw new UserException(ExitCodes.USAGE, "Missing username argument");
} else if (args.size() > 1) {
throw new UserError(ExitCodes.USAGE, "Expected a single username argument, found extra: " + args.toString());
throw new UserException(ExitCodes.USAGE, "Expected a single username argument, found extra: " + args.toString());
}
String username = args.get(0);
Validation.Error validationError = Users.validateUsername(username);
if (validationError != null) {
throw new UserError(ExitCodes.DATA_ERROR, "Invalid username [" + username + "]... " + validationError);
throw new UserException(ExitCodes.DATA_ERROR, "Invalid username [" + username + "]... " + validationError);
}
return username;
}
// pkg private for testing
static char[] parsePassword(Terminal terminal, String passwordStr) throws UserError {
static char[] parsePassword(Terminal terminal, String passwordStr) throws UserException {
char[] password;
if (passwordStr != null) {
password = passwordStr.toCharArray();
Validation.Error validationError = Users.validatePassword(password);
if (validationError != null) {
throw new UserError(ExitCodes.DATA_ERROR, "Invalid password..." + validationError);
throw new UserException(ExitCodes.DATA_ERROR, "Invalid password..." + validationError);
}
} else {
password = terminal.readSecret("Enter new password: ");
Validation.Error validationError = Users.validatePassword(password);
if (validationError != null) {
throw new UserError(ExitCodes.DATA_ERROR, "Invalid password..." + validationError);
throw new UserException(ExitCodes.DATA_ERROR, "Invalid password..." + validationError);
}
char[] retyped = terminal.readSecret("Retype new password: ");
if (Arrays.equals(password, retyped) == false) {
throw new UserError(ExitCodes.DATA_ERROR, "Password mismatch");
throw new UserException(ExitCodes.DATA_ERROR, "Password mismatch");
}
}
return password;
@ -446,7 +446,7 @@ public class UsersTool extends MultiCommand {
}
// pkg private for testing
static String[] parseRoles(Terminal terminal, Environment env, String rolesStr) throws UserError {
static String[] parseRoles(Terminal terminal, Environment env, String rolesStr) throws UserException {
if (rolesStr.isEmpty()) {
return Strings.EMPTY_ARRAY;
}
@ -454,7 +454,7 @@ public class UsersTool extends MultiCommand {
for (String role : roles) {
Validation.Error validationError = Validation.Roles.validateRoleName(role);
if (validationError != null) {
throw new UserError(ExitCodes.DATA_ERROR, "Invalid role [" + role + "]... " + validationError);
throw new UserException(ExitCodes.DATA_ERROR, "Invalid role [" + role + "]... " + validationError);
}
}

View File

@ -7,12 +7,10 @@ package org.elasticsearch.xpack.security.crypto.tool;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import joptsimple.util.KeyValuePair;
import org.elasticsearch.cli.Command;
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.SuppressForbidden;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.settings.Settings;
@ -26,7 +24,6 @@ import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFilePermission;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -65,7 +62,7 @@ public class SystemKeyTool extends SettingCommand {
if (options.hasArgument(arguments)) {
List<String> args = arguments.values(options);
if (args.size() > 1) {
throw new UserError(ExitCodes.USAGE, "No more than one key path can be supplied");
throw new UserException(ExitCodes.USAGE, "No more than one key path can be supplied");
}
keyPath = parsePath(args.get(0));
} else {

View File

@ -11,7 +11,7 @@ import org.apache.lucene.util.IOUtils;
import org.elasticsearch.cli.Command;
import org.elasticsearch.cli.CommandTestCase;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.UserError;
import org.elasticsearch.cli.UserException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.PathUtilsForTesting;
import org.elasticsearch.common.settings.Settings;
@ -174,7 +174,7 @@ public class UsersToolTests extends CommandTestCase {
}
public void testParseInvalidUsername() throws Exception {
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
UsersTool.parseUsername(Collections.singletonList("$34dkl"));
});
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
@ -182,7 +182,7 @@ public class UsersToolTests extends CommandTestCase {
}
public void testParseUsernameMissing() throws Exception {
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
UsersTool.parseUsername(Collections.emptyList());
});
assertEquals(ExitCodes.USAGE, e.exitCode);
@ -190,7 +190,7 @@ public class UsersToolTests extends CommandTestCase {
}
public void testParseUsernameExtraArgs() throws Exception {
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
UsersTool.parseUsername(Arrays.asList("username", "extra"));
});
assertEquals(ExitCodes.USAGE, e.exitCode);
@ -198,7 +198,7 @@ public class UsersToolTests extends CommandTestCase {
}
public void testParseInvalidPasswordOption() throws Exception {
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
UsersTool.parsePassword(terminal, "123");
});
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
@ -207,7 +207,7 @@ public class UsersToolTests extends CommandTestCase {
public void testParseInvalidPasswordInput() throws Exception {
terminal.addSecretInput("123");
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
UsersTool.parsePassword(terminal, null);
});
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
@ -217,7 +217,7 @@ public class UsersToolTests extends CommandTestCase {
public void testParseMismatchPasswordInput() throws Exception {
terminal.addSecretInput("password1");
terminal.addSecretInput("password2");
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
UsersTool.parsePassword(terminal, null);
});
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
@ -239,7 +239,7 @@ public class UsersToolTests extends CommandTestCase {
}
public void testParseInvalidRole() throws Exception {
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
UsersTool.parseRoles(terminal, new Environment(settings), "$345");
});
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
@ -266,7 +266,7 @@ public class UsersToolTests extends CommandTestCase {
}
public void testUseraddUserExists() throws Exception {
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
execute("useradd", pathHomeParameter, fileTypeParameter, "existing_user", "-p", "changeme");
});
assertEquals(ExitCodes.CODE_ERROR, e.exitCode);
@ -282,7 +282,7 @@ public class UsersToolTests extends CommandTestCase {
}
public void testUserdelUnknownUser() throws Exception {
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
execute("userdel", pathHomeParameter, fileTypeParameter, "unknown");
});
assertEquals(ExitCodes.NO_USER, e.exitCode);
@ -295,7 +295,7 @@ public class UsersToolTests extends CommandTestCase {
}
public void testPasswdUnknownUser() throws Exception {
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
execute("passwd", pathHomeParameter, fileTypeParameter, "unknown", "-p", "changeme");
});
assertEquals(ExitCodes.NO_USER, e.exitCode);
@ -317,7 +317,7 @@ public class UsersToolTests extends CommandTestCase {
}
public void testRolesUnknownUser() throws Exception {
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
execute("roles", pathHomeParameter, fileTypeParameter, "unknown");
});
assertEquals(ExitCodes.NO_USER, e.exitCode);
@ -354,7 +354,7 @@ public class UsersToolTests extends CommandTestCase {
}
public void testListUnknownUser() throws Exception {
UserError e = expectThrows(UserError.class, () -> {
UserException e = expectThrows(UserException.class, () -> {
execute("list", pathHomeParameter, fileTypeParameter, "unknown");
});
assertEquals(ExitCodes.NO_USER, e.exitCode);

View File

@ -13,7 +13,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.io.FileSystemUtils;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
@ -83,7 +83,7 @@ final class InstallXPackExtensionCommand 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 extension id argument");
throw new UserException(ExitCodes.USAGE, "Must supply a single extension id argument");
}
String extensionURL = args.get(0);
boolean isBatch = options.has(batchOption) || System.console() == null;
@ -116,7 +116,7 @@ final class InstallXPackExtensionCommand extends SettingCommand {
return zip;
}
private Path unzip(Path zip, Path extensionDir) throws IOException, UserError {
private Path unzip(Path zip, Path extensionDir) throws IOException, UserException {
// unzip extension to a staging temp dir
Path target = Files.createTempDirectory(extensionDir, ".installing-");
Files.createDirectories(target);
@ -195,7 +195,7 @@ final class InstallXPackExtensionCommand extends SettingCommand {
XPackExtensionInfo info = verify(terminal, tmpRoot, env, isBatch);
final Path destination = resolveXPackExtensionsFile(env).resolve(info.getName());
if (Files.exists(destination)) {
throw new UserError(ExitCodes.USAGE,
throw new UserException(ExitCodes.USAGE,
"extension directory " + destination.toAbsolutePath() +
" already exists. To update the extension, uninstall it first using 'remove " +
info.getName() + "' command");

View File

@ -11,7 +11,7 @@ import org.apache.lucene.util.IOUtils;
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.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
@ -44,7 +44,7 @@ class RemoveXPackExtensionCommand 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 extension id argument");
throw new UserException(ExitCodes.USAGE, "Must supply a single extension id argument");
}
execute(terminal, args.get(0), settings);
}
@ -56,7 +56,7 @@ class RemoveXPackExtensionCommand extends SettingCommand {
Environment env = InternalSettingsPreparer.prepareEnvironment(Settings.EMPTY, terminal, settings);
Path extensionDir = resolveXPackExtensionsFile(env).resolve(extensionName);
if (Files.exists(extensionDir) == false) {
throw new UserError(ExitCodes.USAGE,
throw new UserException(ExitCodes.USAGE,
"Extension " + extensionName + " not found. Run 'bin/x-pack/extension list' to get list of installed extensions.");
}

View File

@ -8,7 +8,7 @@ package org.elasticsearch.xpack.extensions;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.Version;
import org.elasticsearch.cli.MockTerminal;
import org.elasticsearch.cli.UserError;
import org.elasticsearch.cli.UserException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.test.ESTestCase;
@ -162,7 +162,7 @@ public class InstallXPackExtensionCommandTests extends ESTestCase {
public void testExistingExtension() throws Exception {
String extZip = createExtension("fake", createTempDir());
installExtension(extZip, home);
UserError e = expectThrows(UserError.class, () -> installExtension(extZip, home));
UserException e = expectThrows(UserException.class, () -> installExtension(extZip, home));
assertTrue(e.getMessage(), e.getMessage().contains("already exists"));
assertInstallCleaned(env);
}

View File

@ -7,7 +7,7 @@ package org.elasticsearch.xpack.extensions;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.cli.MockTerminal;
import org.elasticsearch.cli.UserError;
import org.elasticsearch.cli.UserException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.test.ESTestCase;
@ -58,7 +58,7 @@ public class RemoveXPackExtensionCommandTests extends ESTestCase {
public void testMissing() throws Exception {
Path extDir = createExtensionDir(env);
UserError e = expectThrows(UserError.class, () -> removeExtension("dne", home));
UserException e = expectThrows(UserException.class, () -> removeExtension("dne", home));
assertTrue(e.getMessage(), e.getMessage().contains("Extension dne not found"));
assertRemoveCleaned(extDir);
}

View File

@ -12,7 +12,7 @@ import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.elasticsearch.cli.Command;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.UserError;
import org.elasticsearch.cli.UserException;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.xpack.watcher.trigger.schedule.Cron;
import org.joda.time.DateTime;
@ -46,7 +46,7 @@ public class CronEvalTool extends Command {
int count = Integer.parseInt(countOption.value(options));
List<String> args = arguments.values(options);
if (args.size() != 1) {
throw new UserError(ExitCodes.USAGE, "expecting a single argument that is the cron expression to evaluate");
throw new UserException(ExitCodes.USAGE, "expecting a single argument that is the cron expression to evaluate");
}
execute(terminal, args.get(0), count);
}
@ -65,7 +65,7 @@ public class CronEvalTool extends Command {
long prevTime = time;
time = cron.getNextValidTimeAfter(time);
if (time < 0) {
throw new UserError(ExitCodes.OK, (i + 1) + ".\t Could not compute future times since ["
throw new UserException(ExitCodes.OK, (i + 1) + ".\t Could not compute future times since ["
+ formatter.print(prevTime) + "] " + "(perhaps the cron expression only points to times in the past?)");
}
terminal.println((i+1) + ".\t" + formatter.print(time));