This is an automated email from the ASF dual-hosted git repository.

jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new 286286d78 [#5808] fix(CLI): Fix improper exception throwing When a 
malformed name is passed to the CLI command (#5836)
286286d78 is described below

commit 286286d78642958cd1223de46d07b2e27003fc49
Author: Lord of Abyss <[email protected]>
AuthorDate: Tue Dec 17 12:15:06 2024 +0800

    [#5808] fix(CLI): Fix improper exception throwing When a malformed name is 
passed to the CLI command (#5836)
    
    ### What changes were proposed in this pull request?
    
    No exception should be thrown when a malformed name is passed to the
    CLI. Currently, passing a malformed name causes an
    IllegalNamespaceException. I’ve added error messages to inform the user
    when necessary arguments are missing.
    
    Additionally, the `FullName.getNamePart()` method no longer prints error
    messages, as the information it provides is limited. I think performing
    fine-grained argument validation in each method and providing specific
    hints is a better way to hint users.
    
    ### Why are the changes needed?
    
    Fix: #5808
    
    ### Does this PR introduce _any_ user-facing change?
    
    NO
    
    ### How was this patch tested?
    
    ```bash
    bin/gcli.sh table  list -i
    # output: Missing required argument(s): METALAKE, CATALOG, SCHEMA
    
    bin/gcli.sh table  list -i --metalake demo_metalake
    # output: Missing required argument(s): CATALOG, SCHEMA
    
    bin/gcli.sh table  list -i --metalake demo_metalake --name Hive_catalog
    # output: Missing required argument(s): SCHEMA
    
    bin/gcli.sh table  list -i --metalake demo_metalake --name 
Hive_catalog.default
    # output: correct result
    ```
---
 .../org/apache/gravitino/cli/GravitinoCommandLine.java   | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

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 0df9eab82..ab22a5d96 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
@@ -27,8 +27,11 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.Options;
@@ -321,6 +324,19 @@ public class GravitinoCommandLine extends 
TestableCommandLine {
     Command.setAuthenticationMode(auth, userName);
 
     if (CommandActions.LIST.equals(command)) {
+      List<String> missingEntities =
+          Stream.of(
+                  metalake == null ? CommandEntities.METALAKE : null,
+                  catalog == null ? CommandEntities.CATALOG : null,
+                  schema == null ? CommandEntities.SCHEMA : null)
+              .filter(Objects::nonNull)
+              .collect(Collectors.toList());
+      if (!missingEntities.isEmpty()) {
+        System.err.println(
+            "Missing required argument(s): " + Joiner.on(", 
").join(missingEntities));
+        return;
+      }
+
       newListTables(url, ignore, metalake, catalog, schema).handle();
       return;
     }

Reply via email to