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 07fb3dddd9 [#9125] Replace UNKNOWN_USER with UNKNOWN_ENTITY in
NoSuchMetadataObjectException (#9131)
07fb3dddd9 is described below
commit 07fb3dddd9329eab5d54b1d755614e965ceea899
Author: Harsh Mehta <[email protected]>
AuthorDate: Sun Nov 16 03:13:51 2025 +0530
[#9125] Replace UNKNOWN_USER with UNKNOWN_ENTITY in
NoSuchMetadataObjectException (#9131)
This PR refactors - NoSuchMetadataObjectException refers strictly to
missing metadata entities and not to users.
This patch replaces `UNKNOWN_USER` with `UNKNOWN_ENTITY` to more
accurately represent the failure condition and align with naming
semantics
Signed-off-by: Harsh Mehta <[email protected]>
---
.../cli/commands/RevokePrivilegesFromRole.java | 2 +-
.../org/apache/gravitino/cli/TestRoleCommands.java | 25 ++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
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 1874b6d904..8952d5ef70 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
@@ -89,7 +89,7 @@ public class RevokePrivilegesFromRole extends MetadataCommand
{
} catch (NoSuchRoleException err) {
exitWithError(ErrorMessages.UNKNOWN_ROLE);
} catch (NoSuchMetadataObjectException err) {
- exitWithError(ErrorMessages.UNKNOWN_USER);
+ exitWithError(ErrorMessages.UNKNOWN_ENTITY);
} 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 3db21198ef..8d21679688 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
@@ -48,6 +48,7 @@ import
org.apache.gravitino.cli.commands.RevokePrivilegesFromRole;
import org.apache.gravitino.cli.commands.RoleAudit;
import org.apache.gravitino.cli.commands.RoleDetails;
import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -423,4 +424,28 @@ class TestRoleCommands {
RuntimeException thrown = assertThrows(RuntimeException.class,
commandLine::handleCommandLine);
assertEquals(org.apache.gravitino.cli.ErrorMessages.UNKNOWN_ROLE,
thrown.getMessage());
}
+
+ @Test
+ void
testRevokePrivilegesFromRoleNoSuchMetadataObjectExceptionShowsUnknownEntity() {
+ Main.useExit = false;
+ RoleDetails details =
+ spy(new RoleDetails(mock(CommandContext.class), "metalake_demo",
"admin"));
+ doThrow(new
org.apache.gravitino.exceptions.NoSuchMetadataObjectException("Unknown
entity."))
+ .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);
+ Assertions.assertEquals(ErrorMessages.UNKNOWN_ENTITY, thrown.getMessage());
+ }
}