From 900fef329c3b20d9eb68a8ca2d47c87ab8843a61 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Mon, 6 Jan 2025 13:30:13 +1100 Subject: [PATCH] [#6103] Clean up error messages in Gravitino CLI (#6108) What changes were proposed in this pull request? Clean up the error messages. ### Why are the changes needed? Put them all in one place and made more consistent. Fix: #6103 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Tested locally. --- .../apache/gravitino/cli/ErrorMessages.java | 92 +++++++++++-------- .../gravitino/cli/GravitinoCommandLine.java | 10 +- .../java/org/apache/gravitino/cli/Main.java | 2 +- .../org/apache/gravitino/cli/Privileges.java | 2 +- .../gravitino/cli/commands/Command.java | 3 +- .../gravitino/cli/commands/CreateTag.java | 2 +- .../gravitino/cli/commands/DeleteCatalog.java | 2 +- .../cli/commands/DeleteMetalake.java | 2 +- .../gravitino/cli/commands/DeleteTag.java | 2 +- .../cli/commands/GrantPrivilegesToRole.java | 2 +- .../gravitino/cli/commands/RegisterModel.java | 2 +- .../commands/RevokePrivilegesFromRole.java | 2 +- .../gravitino/cli/TestCatalogCommands.java | 6 +- .../gravitino/cli/TestColumnCommands.java | 14 +-- .../gravitino/cli/TestFilesetCommands.java | 10 +- .../org/apache/gravitino/cli/TestMain.java | 4 +- .../gravitino/cli/TestMetalakeCommands.java | 2 +- .../gravitino/cli/TestModelCommands.java | 10 +- .../gravitino/cli/TestSchemaCommands.java | 6 +- .../gravitino/cli/TestTableCommands.java | 10 +- .../apache/gravitino/cli/TestTagCommands.java | 6 +- .../gravitino/cli/TestTopicCommands.java | 10 +- 22 files changed, 109 insertions(+), 92 deletions(-) diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java b/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java index 7fd4e272217..10b1e9579a0 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java @@ -21,51 +21,67 @@ /* User friendly error messages. */ public class ErrorMessages { - public static final String UNSUPPORTED_COMMAND = "Unsupported or unknown command."; - public static final String UNKNOWN_ENTITY = "Unknown entity."; - public static final String TOO_MANY_ARGUMENTS = "Too many arguments."; - public static final String UNKNOWN_METALAKE = "Unknown metalake name."; - public static final String UNKNOWN_CATALOG = "Unknown catalog name."; - public static final String UNKNOWN_SCHEMA = "Unknown schema name."; - public static final String UNKNOWN_TABLE = "Unknown table name."; - public static final String UNKNOWN_MODEL = "Unknown model name."; + public static final String CATALOG_EXISTS = "Catalog already exists."; + public static final String COLUMN_EXISTS = "Column already exists."; + public static final String FILESET_EXISTS = "Fileset already exists."; + public static final String GROUP_EXISTS = "Group already exists."; + public static final String METALAKE_EXISTS = "Metalake already exists."; + public static final String MODEL_EXISTS = "Model already exists."; + public static final String ROLE_EXISTS = "Role already exists."; + public static final String SCHEMA_EXISTS = "Schema already exists."; + public static final String TABLE_EXISTS = "Table already exists."; + public static final String TAG_EXISTS = "Tag already exists."; + public static final String TOPIC_EXISTS = "Topic already exists."; + public static final String USER_EXISTS = "User already exists."; + + public static final String ENTITY_IN_USE = " in use, please disable it first."; + + public static final String INVALID_ENABLE_DISABLE = + "Unable to us --enable and --disable at the same time"; + public static final String INVALID_OWNER_COMMAND = + "Unsupported combination of options either use --user or --group."; + public static final String INVALID_REMOVE_COMMAND = + "Unsupported combination of options either use --name or --property."; + public static final String INVALID_SET_COMMAND = + "Unsupported combination of options either use --name, --user, --group or --property and --value."; + + public static final String HELP_FAILED = "Failed to load help message: "; + public static final String MALFORMED_NAME = "Malformed entity name."; - public static final String MISSING_NAME = "Missing --name option."; - public static final String MISSING_METALAKE = "Missing --metalake option."; + public static final String MISSING_ENTITIES = "Missing required entity names: "; + public static final String MISSING_GROUP = "Missing --group option."; - public static final String MISSING_USER = "Missing --user option."; + public static final String MISSING_METALAKE = "Missing --metalake option."; + public static final String MISSING_NAME = "Missing --name option."; + public static final String MISSING_PROPERTY = "Missing --property option."; public static final String MISSING_ROLE = "Missing --role option."; public static final String MISSING_TAG = "Missing --tag option."; public static final String MISSING_URI = "Missing --uri option."; - public static final String MISSING_PROPERTY = "Missing --property option."; + public static final String MISSING_USER = "Missing --user option."; public static final String MISSING_VALUE = "Missing --value option."; - public static final String METALAKE_EXISTS = "Metalake already exists."; - public static final String CATALOG_EXISTS = "Catalog already exists."; - public static final String SCHEMA_EXISTS = "Schema already exists."; - public static final String UNKNOWN_USER = "Unknown user."; - public static final String USER_EXISTS = "User already exists."; - public static final String UNKNOWN_GROUP = "Unknown group."; - public static final String GROUP_EXISTS = "Group already exists."; - public static final String UNKNOWN_TAG = "Unknown tag."; + public static final String MULTIPLE_TAG_COMMAND_ERROR = - "Error: The current command only supports one --tag option."; - public static final String TAG_EXISTS = "Tag already exists."; - public static final String UNKNOWN_COLUMN = "Unknown column."; - public static final String COLUMN_EXISTS = "Column already exists."; - public static final String UNKNOWN_TOPIC = "Unknown topic."; - public static final String TOPIC_EXISTS = "Topic already exists."; - public static final String MODEL_EXISTS = "Model already exists."; - public static final String UNKNOWN_FILESET = "Unknown fileset."; - public static final String FILESET_EXISTS = "Fileset already exists."; - public static final String TAG_EMPTY = "Error: Must configure --tag option."; + "This command only supports one --tag option."; + + public static final String REGISTER_FAILED = "Failed to register model: "; + + public static final String UNKNOWN_CATALOG = "Unknown catalog name."; + public static final String UNKNOWN_COLUMN = "Unknown column name."; + public static final String UNKNOWN_ENTITY = "Unknown entity."; + public static final String UNKNOWN_FILESET = "Unknown fileset name."; + public static final String UNKNOWN_GROUP = "Unknown group."; + public static final String UNKNOWN_METALAKE = "Unknown metalake name."; + public static final String UNKNOWN_MODEL = "Unknown model name."; + public static final String UNKNOWN_PRIVILEGE = "Unknown privilege"; public static final String UNKNOWN_ROLE = "Unknown role."; - public static final String ROLE_EXISTS = "Role already exists."; - public static final String TABLE_EXISTS = "Table already exists."; - public static final String INVALID_SET_COMMAND = - "Unsupported combination of options either use --name, --user, --group or --property and --value."; - public static final String INVALID_REMOVE_COMMAND = - "Unsupported combination of options either use --name or --property."; - public static final String INVALID_OWNER_COMMAND = - "Unsupported combination of options either use --user or --group."; + public static final String UNKNOWN_SCHEMA = "Unknown schema name."; + public static final String UNKNOWN_TABLE = "Unknown table name."; + public static final String UNKNOWN_TAG = "Unknown tag."; + public static final String UNKNOWN_TOPIC = "Unknown topic name."; + public static final String UNKNOWN_USER = "Unknown user."; + + public static final String PARSE_ERROR = "Error parsing command line: "; + public static final String TOO_MANY_ARGUMENTS = "Too many arguments."; public static final String UNSUPPORTED_ACTION = "Entity doesn't support this action."; + public static final String UNSUPPORTED_COMMAND = "Unsupported or unknown command."; } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java index c545fbe2430..e19cc733f21 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java @@ -211,7 +211,7 @@ private void handleMetalakeCommand() { case CommandActions.UPDATE: if (line.hasOption(GravitinoOptions.ENABLE) && line.hasOption(GravitinoOptions.DISABLE)) { - System.err.println("Unable to enable and disable at the same time"); + System.err.println(ErrorMessages.INVALID_ENABLE_DISABLE); Main.exit(-1); } if (line.hasOption(GravitinoOptions.ENABLE)) { @@ -304,7 +304,7 @@ private void handleCatalogCommand() { case CommandActions.UPDATE: if (line.hasOption(GravitinoOptions.ENABLE) && line.hasOption(GravitinoOptions.DISABLE)) { - System.err.println("Unable to enable and disable at the same time"); + System.err.println(ErrorMessages.INVALID_ENABLE_DISABLE); Main.exit(-1); } if (line.hasOption(GravitinoOptions.ENABLE)) { @@ -673,7 +673,7 @@ protected void handleTagCommand() { } newTagEntity(url, ignore, metalake, name, tags).handle(); } else { - System.err.println("The set command only supports tag properties or attaching tags."); + System.err.println(ErrorMessages.INVALID_SET_COMMAND); Main.exit(-1); } break; @@ -932,7 +932,7 @@ private void handleHelpCommand() { } System.out.print(helpMessage.toString()); } catch (IOException e) { - System.err.println("Failed to load help message: " + e.getMessage()); + System.err.println(ErrorMessages.HELP_FAILED + e.getMessage()); Main.exit(-1); } } @@ -1309,7 +1309,7 @@ public String getAuth() { private void checkEntities(List entities) { if (!entities.isEmpty()) { - System.err.println("Missing required argument(s): " + COMMA_JOINER.join(entities)); + System.err.println(ErrorMessages.MISSING_ENTITIES + COMMA_JOINER.join(entities)); Main.exit(-1); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java b/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java index 1f4a3926ef5..8c28d7e8a29 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java @@ -56,7 +56,7 @@ public static void main(String[] args) { commandLine.handleSimpleLine(); } } catch (ParseException exp) { - System.err.println("Error parsing command line: " + exp.getMessage()); + System.err.println(ErrorMessages.PARSE_ERROR + exp.getMessage()); GravitinoCommandLine.displayHelp(options); exit(-1); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/Privileges.java b/clients/cli/src/main/java/org/apache/gravitino/cli/Privileges.java index 9d47d8fc9c8..fa904663318 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/Privileges.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/Privileges.java @@ -112,7 +112,7 @@ public static Privilege.Name toName(String privilege) { case MANAGE_GRANTS: return Privilege.Name.MANAGE_GRANTS; default: - System.err.println("Unknown privilege"); + System.err.println(ErrorMessages.UNKNOWN_PRIVILEGE + " " + privilege); return null; } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java index cb11d7dfcef..d881a1dbcd6 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java @@ -23,6 +23,7 @@ import com.google.common.base.Joiner; import java.io.File; +import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.cli.GravitinoConfig; import org.apache.gravitino.cli.KerberosData; import org.apache.gravitino.cli.Main; @@ -205,6 +206,6 @@ protected void output(T entity) { } protected String getMissingEntitiesInfo(String... entities) { - return "Missing required argument(s): " + COMMA_JOINER.join(entities); + return ErrorMessages.MISSING_ENTITIES + COMMA_JOINER.join(entities); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java index 0dd4289bb75..87ab0da779d 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java @@ -53,7 +53,7 @@ public CreateTag( @Override public void handle() { if (tags == null || tags.length == 0) { - System.err.println(ErrorMessages.TAG_EMPTY); + System.err.println(ErrorMessages.MISSING_TAG); } else { boolean hasOnlyOneTag = tags.length == 1; if (hasOnlyOneTag) { diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteCatalog.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteCatalog.java index 6aa8e5ad904..7cb9bf7d9c8 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteCatalog.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteCatalog.java @@ -66,7 +66,7 @@ public void handle() { } catch (NoSuchCatalogException err) { exitWithError(ErrorMessages.UNKNOWN_CATALOG); } catch (CatalogInUseException catalogInUseException) { - System.err.println(catalog + " in use, please disable it first."); + System.err.println(catalog + ErrorMessages.ENTITY_IN_USE); } catch (Exception exp) { exitWithError(exp.getMessage()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java index e88ae41486f..3bad108a9ec 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java @@ -58,7 +58,7 @@ public void handle() { } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); } catch (MetalakeInUseException inUseException) { - System.err.println(metalake + " in use, please disable it first."); + System.err.println(metalake + ErrorMessages.ENTITY_IN_USE); } catch (Exception exp) { exitWithError(exp.getMessage()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java index d3db384c094..1e05292c82a 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java @@ -59,7 +59,7 @@ public void handle() { } if (tags == null || tags.length == 0) { - System.err.println(ErrorMessages.TAG_EMPTY); + System.err.println(ErrorMessages.MISSING_TAG); } else { boolean hasOnlyOneTag = tags.length == 1; if (hasOnlyOneTag) { diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GrantPrivilegesToRole.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GrantPrivilegesToRole.java index e3c9fa4944e..584e073beac 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GrantPrivilegesToRole.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GrantPrivilegesToRole.java @@ -73,7 +73,7 @@ public void handle() { for (String privilege : privileges) { if (!Privileges.isValid(privilege)) { - System.err.println("Unknown privilege " + privilege); + System.err.println(ErrorMessages.UNKNOWN_PRIVILEGE + " " + privilege); return; } PrivilegeDTO privilegeDTO = diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RegisterModel.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RegisterModel.java index d50dbed50e2..7c8cd120bf4 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RegisterModel.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RegisterModel.java @@ -96,7 +96,7 @@ public void handle() { if (registeredModel != null) { System.out.println("Successful register " + registeredModel.name() + "."); } else { - System.err.println("Failed to register model: " + model + "."); + System.err.println(ErrorMessages.REGISTER_FAILED + model + "."); Main.exit(-1); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RevokePrivilegesFromRole.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RevokePrivilegesFromRole.java index 8077532319e..a62e977a2fb 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RevokePrivilegesFromRole.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RevokePrivilegesFromRole.java @@ -73,7 +73,7 @@ public void handle() { for (String privilege : privileges) { if (!Privileges.isValid(privilege)) { - System.err.println("Unknown privilege " + privilege); + System.err.println(ErrorMessages.UNKNOWN_PRIVILEGE + " " + privilege); return; } PrivilegeDTO privilegeDTO = diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCatalogCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCatalogCommands.java index 44e5537955f..bd8f30b5adb 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCatalogCommands.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCatalogCommands.java @@ -345,9 +345,9 @@ void testCatalogDetailsCommandWithoutCatalog() { String output = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); assertEquals( output, - "Missing --name option." + ErrorMessages.MISSING_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + CommandEntities.CATALOG); } @@ -436,6 +436,6 @@ void testCatalogWithDisableAndEnableOptions() { GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "catalog", false); verify(commandLine, never()) .newCatalogDisable(GravitinoCommandLine.DEFAULT_URL, false, "melake_demo", "catalog"); - assertTrue(errContent.toString().contains("Unable to enable and disable at the same time")); + assertTrue(errContent.toString().contains(ErrorMessages.INVALID_ENABLE_DISABLE)); } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestColumnCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestColumnCommands.java index b6159343ef0..2d1e12debcf 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestColumnCommands.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestColumnCommands.java @@ -464,7 +464,7 @@ void testDeleteColumnCommandWithoutCatalog() { output, ErrorMessages.MISSING_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ") .join( Arrays.asList( @@ -496,7 +496,7 @@ void testDeleteColumnCommandWithoutSchema() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ") .join( Arrays.asList( @@ -531,7 +531,7 @@ void testDeleteColumnCommandWithoutTable() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ").join(Arrays.asList(CommandEntities.TABLE, CommandEntities.COLUMN))); } @@ -563,7 +563,7 @@ void testDeleteColumnCommandWithoutColumn() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ").join(Arrays.asList(CommandEntities.COLUMN))); } @@ -588,7 +588,7 @@ void testListColumnCommandWithoutCatalog() { output, ErrorMessages.MISSING_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ") .join( Arrays.asList( @@ -617,7 +617,7 @@ void testListColumnCommandWithoutSchema() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ").join(Arrays.asList(CommandEntities.SCHEMA, CommandEntities.TABLE))); } @@ -643,7 +643,7 @@ void testListColumnCommandWithoutTable() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + CommandEntities.TABLE); } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFilesetCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFilesetCommands.java index b46b73cc3dd..1e8c54124c1 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFilesetCommands.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFilesetCommands.java @@ -369,7 +369,7 @@ void testListFilesetCommandWithoutCatalog() { output, ErrorMessages.MISSING_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ").join(Arrays.asList(CommandEntities.CATALOG, CommandEntities.SCHEMA))); } @@ -394,7 +394,7 @@ void testListFilesetCommandWithoutSchema() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ").join(Arrays.asList(CommandEntities.SCHEMA))); } @@ -419,7 +419,7 @@ void testFilesetDetailCommandWithoutCatalog() { output, ErrorMessages.MISSING_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ") .join( Arrays.asList( @@ -448,7 +448,7 @@ void testFilesetDetailCommandWithoutSchema() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ").join(Arrays.asList(CommandEntities.SCHEMA, CommandEntities.FILESET))); } @@ -474,7 +474,7 @@ void testFilesetDetailCommandWithoutFileset() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ").join(Arrays.asList(CommandEntities.FILESET))); } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java index 1d1ffded0ff..c9cd437cf3d 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java @@ -189,7 +189,7 @@ public void CreateTagWithNoTag() { Main.main(args); - assertTrue(errContent.toString().contains(ErrorMessages.TAG_EMPTY)); // Expect error + assertTrue(errContent.toString().contains(ErrorMessages.MISSING_TAG)); // Expect error } @SuppressWarnings("DefaultCharset") @@ -198,6 +198,6 @@ public void DeleteTagWithNoTag() { Main.main(args); - assertTrue(errContent.toString().contains(ErrorMessages.TAG_EMPTY)); // Expect error + assertTrue(errContent.toString().contains(ErrorMessages.MISSING_TAG)); // Expect error } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java index 7df08b8ada5..dae2fe63400 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java @@ -449,6 +449,6 @@ void testMetalakeWithDisableAndEnableOptions() { .newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", false); verify(commandLine, never()) .newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", false); - assertTrue(errContent.toString().contains("Unable to enable and disable at the same time")); + assertTrue(errContent.toString().contains(ErrorMessages.INVALID_ENABLE_DISABLE)); } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestModelCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestModelCommands.java index 79000226013..8d475d3625a 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestModelCommands.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestModelCommands.java @@ -121,7 +121,7 @@ void testListModelCommandWithoutCatalog() { assertEquals( ErrorMessages.MISSING_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + joiner.join(Arrays.asList(CommandEntities.CATALOG, CommandEntities.SCHEMA)), output); } @@ -150,7 +150,7 @@ void testListModelCommandWithoutSchema() { assertEquals( ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + joiner.join(Collections.singletonList(CommandEntities.SCHEMA)), output); } @@ -205,7 +205,7 @@ void testModelDetailsCommandWithoutCatalog() { assertEquals( ErrorMessages.MISSING_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + joiner.join( Arrays.asList( CommandEntities.CATALOG, CommandEntities.SCHEMA, CommandEntities.MODEL)), @@ -238,7 +238,7 @@ void testModelDetailsCommandWithoutSchema() { assertEquals( ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + joiner.join(Arrays.asList(CommandEntities.SCHEMA, CommandEntities.MODEL)), output); } @@ -269,7 +269,7 @@ void testModelDetailsCommandWithoutModel() { assertEquals( ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + joiner.join(Collections.singletonList(CommandEntities.MODEL)), output); } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestSchemaCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestSchemaCommands.java index 190e866355b..b3f67174fbd 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestSchemaCommands.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestSchemaCommands.java @@ -287,7 +287,7 @@ void testListSchemaWithoutCatalog() { verify(commandLine, never()) .newListSchema(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", null); assertTrue( - errContent.toString().contains("Missing required argument(s): " + CommandEntities.CATALOG)); + errContent.toString().contains(ErrorMessages.MISSING_ENTITIES + CommandEntities.CATALOG)); } @Test @@ -308,7 +308,7 @@ void testDetailsSchemaWithoutCatalog() { errContent .toString() .contains( - "Missing required argument(s): " + ErrorMessages.MISSING_ENTITIES + CommandEntities.CATALOG + ", " + CommandEntities.SCHEMA)); @@ -330,6 +330,6 @@ void testDetailsSchemaWithoutSchema() { assertThrows(RuntimeException.class, commandLine::handleCommandLine); assertTrue( - errContent.toString().contains("Missing required argument(s): " + CommandEntities.SCHEMA)); + errContent.toString().contains(ErrorMessages.MISSING_ENTITIES + CommandEntities.SCHEMA)); } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestTableCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestTableCommands.java index c4a8223dd48..946c330178d 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestTableCommands.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestTableCommands.java @@ -457,7 +457,7 @@ void testListTableWithoutCatalog() { output, ErrorMessages.MISSING_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + CommandEntities.CATALOG + ", " + CommandEntities.SCHEMA); @@ -485,7 +485,7 @@ void testListTableWithoutSchema() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + CommandEntities.SCHEMA); } @@ -510,7 +510,7 @@ void testDetailTableWithoutCatalog() { output, ErrorMessages.MISSING_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + CommandEntities.CATALOG + ", " + CommandEntities.SCHEMA @@ -539,7 +539,7 @@ void testDetailTableWithoutSchema() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + CommandEntities.SCHEMA + ", " + CommandEntities.TABLE); @@ -568,7 +568,7 @@ void testDetailTableWithoutTable() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + CommandEntities.TABLE); } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestTagCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestTagCommands.java index 74932ca87b3..3279c23d141 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestTagCommands.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestTagCommands.java @@ -322,7 +322,7 @@ void testSetTagPropertyCommandWithoutPropertyOption() { isNull(), eq("value")); String output = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); - assertEquals(output, "The set command only supports tag properties or attaching tags."); + assertEquals(output, ErrorMessages.INVALID_SET_COMMAND); } @Test @@ -350,7 +350,7 @@ void testSetTagPropertyCommandWithoutValueOption() { eq("property"), isNull()); String output = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); - assertEquals(output, "The set command only supports tag properties or attaching tags."); + assertEquals(output, ErrorMessages.INVALID_SET_COMMAND); } @Test @@ -371,7 +371,7 @@ void testSetMultipleTagPropertyCommandError() { Assertions.assertThrows( IllegalArgumentException.class, () -> commandLine.handleCommandLine(), - "Error: The current command only supports one --tag option."); + ErrorMessages.MULTIPLE_TAG_COMMAND_ERROR); } @Test diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestTopicCommands.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestTopicCommands.java index 7fa2e453f32..c886b4f8ede 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestTopicCommands.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestTopicCommands.java @@ -317,7 +317,7 @@ void testListTopicCommandWithoutCatalog() { output, ErrorMessages.MISSING_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ").join(Arrays.asList(CommandEntities.CATALOG, CommandEntities.SCHEMA))); } @@ -342,7 +342,7 @@ void testListTopicCommandWithoutSchema() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ").join(Arrays.asList(CommandEntities.SCHEMA))); } @@ -367,7 +367,7 @@ void testTopicDetailsCommandWithoutCatalog() { output, ErrorMessages.MISSING_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ") .join( Arrays.asList( @@ -396,7 +396,7 @@ void testTopicDetailsCommandWithoutSchema() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ").join(Arrays.asList(CommandEntities.SCHEMA, CommandEntities.TOPIC))); } @@ -422,7 +422,7 @@ void testTopicDetailsCommandWithoutTopic() { output, ErrorMessages.MALFORMED_NAME + "\n" - + "Missing required argument(s): " + + ErrorMessages.MISSING_ENTITIES + Joiner.on(", ").join(Arrays.asList(CommandEntities.TOPIC))); } }