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 be24d340a9 [#8157]Improvement: exception handling in RoleDetails for 
Unknown Role (#8191)
be24d340a9 is described below

commit be24d340a9e0c7dbaf19c43be9f80100fecb1cb0
Author: Sambhavi Pandey <[email protected]>
AuthorDate: Tue Aug 26 19:34:48 2025 +0530

    [#8157]Improvement: exception handling in RoleDetails for Unknown Role 
(#8191)
    
    ### What changes were proposed in this pull request?
    Exception handing for NoSuchUserException for Unknown Role
    
    ### Why are the changes needed?
    The NoSuchUserException is exiting with error
    ErrorMessages.UNKNOWN_GROUP, but should be about the role.
    
    
    Fix: #8157
    
    ### Does this PR introduce _any_ user-facing change?
    
    ### How was this patch tested?
    Unit testing
---
 .../apache/gravitino/cli/commands/RoleDetails.java |  6 +++---
 .../org/apache/gravitino/cli/TestRoleCommands.java | 25 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RoleDetails.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RoleDetails.java
index 1ab9ec854b..57e79131eb 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RoleDetails.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RoleDetails.java
@@ -25,7 +25,7 @@ import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoClient;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
-import org.apache.gravitino.exceptions.NoSuchUserException;
+import org.apache.gravitino.exceptions.NoSuchRoleException;
 
 public class RoleDetails extends Command {
 
@@ -55,8 +55,8 @@ public class RoleDetails extends Command {
       objects = client.getRole(role).securableObjects();
     } catch (NoSuchMetalakeException err) {
       exitWithError(ErrorMessages.UNKNOWN_METALAKE);
-    } catch (NoSuchUserException err) {
-      exitWithError(ErrorMessages.UNKNOWN_GROUP);
+    } catch (NoSuchRoleException err) {
+      exitWithError(ErrorMessages.UNKNOWN_ROLE);
     } catch (Exception exp) {
       exitWithError(exp.getMessage());
     }
diff --git 
a/clients/cli/src/test/java/org/apache/gravitino/cli/TestRoleCommands.java 
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestRoleCommands.java
index 845c7bea7f..3db21198ef 100644
--- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestRoleCommands.java
+++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestRoleCommands.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.argThat;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -398,4 +399,28 @@ class TestRoleCommands {
     String output = new String(errContent.toByteArray(), 
StandardCharsets.UTF_8).trim();
     assertEquals(output, ErrorMessages.MISSING_ROLE);
   }
+
+  @Test
+  void testRoleDetailsCommandNoSuchUserExceptionShowsUnknownRole() {
+    Main.useExit = false;
+    RoleDetails details =
+        spy(new RoleDetails(mock(CommandContext.class), "metalake_demo", 
"admin"));
+    doThrow(new org.apache.gravitino.exceptions.NoSuchRoleException("Unknown 
role."))
+        .when(details)
+        .handle();
+    
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);
+    
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");
+    when(mockCommandLine.hasOption(GravitinoOptions.ROLE)).thenReturn(true);
+    
when(mockCommandLine.getOptionValues(GravitinoOptions.ROLE)).thenReturn(new 
String[] {"admin"});
+    GravitinoCommandLine commandLine =
+        spy(
+            new GravitinoCommandLine(
+                mockCommandLine, mockOptions, CommandEntities.ROLE, 
CommandActions.DETAILS));
+    doReturn(details)
+        .when(commandLine)
+        .newRoleDetails(any(CommandContext.class), eq("metalake_demo"), 
eq("admin"));
+    doReturn(details).when(details).validate();
+    RuntimeException thrown = assertThrows(RuntimeException.class, 
commandLine::handleCommandLine);
+    assertEquals(org.apache.gravitino.cli.ErrorMessages.UNKNOWN_ROLE, 
thrown.getMessage());
+  }
 }

Reply via email to