jerryshao commented on code in PR #14669:
URL: https://github.com/apache/gravitino/pull/14669#discussion_r4490815831
##########
server-common/src/main/java/org/apache/gravitino/server/authorization/expression/AuthorizationExpressionEvaluator.java:
##########
@@ -183,8 +185,15 @@ private boolean evaluate(
metadataNames.forEach(
(type, entityNameIdent) -> {
if (isMetadataType(type)) {
- MetadataObject metadataObject =
- NameIdentifierUtil.toMetadataObject(entityNameIdent, type);
+ MetadataObject metadataObject;
+ try {
+ metadataObject =
NameIdentifierUtil.toMetadataObject(entityNameIdent, type);
+ } catch (IllegalNameIdentifierException e) {
+ throw e;
+ } catch (IllegalArgumentException e) {
+ // Only metadata-name parsing failures are client errors, not
authorizer failures.
+ throw new IllegalMetadataObjectException(e, "%s",
e.getMessage());
Review Comment:
[Question] The evaluator is also used outside GravitinoInterceptionService:
MetadataAuthzHelper (parent-scope check and list filtering), the Lance
interceptor, and the Iceberg authz handlers. Those paths do not catch
IllegalMetadataObjectException, so a blank name there still ends up as whatever
their generic handler does (likely 500), only with a different exception
subtype. Is it intended that the 400 mapping covers only the Gravitino REST
interceptor? If the Lance and Iceberg servers can receive blank names, the same
change would be needed there. I did not find a failing case; this comes from
reading their catch blocks.
##########
server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java:
##########
@@ -1048,7 +1049,11 @@ public Response handle(OperationType op, String
semanticModel, String schema, Ex
String errorMsg = getSemanticModelErrorMsg(formatted, op.name(), schema,
getErrorMsg(e));
LOG.warn(errorMsg, e);
- if (e instanceof IllegalArgumentException) {
+ if (e instanceof IllegalMetadataObjectException) {
+ // Preserve the existing response type for source-name validation
failures.
Review Comment:
[Nit] Wrapping changes the exception class that reaches resource-level
handlers. About 24 other handlers in this file use `instanceof
IllegalArgumentException` followed by `Utils.illegalArguments(msg, e)`, which
uses `e.getClass().getSimpleName()` as the response `type`. Only SemanticModel
is special-cased here. If any other resource path can propagate this wrapped
exception, its type string changes from `IllegalArgumentException` to
`IllegalMetadataObjectException`. Consider making this uniform, for example by
normalizing the type in `Utils.illegalArguments(String, Throwable)` for
IllegalMetadataObjectException, or confirm that no other handler can receive it.
##########
server-common/src/main/java/org/apache/gravitino/server/authorization/expression/AuthorizationExpressionEvaluator.java:
##########
@@ -183,8 +185,15 @@ private boolean evaluate(
metadataNames.forEach(
(type, entityNameIdent) -> {
if (isMetadataType(type)) {
- MetadataObject metadataObject =
- NameIdentifierUtil.toMetadataObject(entityNameIdent, type);
+ MetadataObject metadataObject;
+ try {
+ metadataObject =
NameIdentifierUtil.toMetadataObject(entityNameIdent, type);
+ } catch (IllegalNameIdentifierException e) {
+ throw e;
+ } catch (IllegalArgumentException e) {
Review Comment:
[Question] This catches any IllegalArgumentException from toMetadataObject
and treats it as a client error. Is toMetadataObject guaranteed to throw
IllegalArgumentException only for bad names, and never for an unsupported
entity type or an internal mapping bug? A server-side bug would now return 400
instead of 500. I read the blank-name path (MetadataObjects.java:181) and it is
fine, but I did not audit every branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]