geyanggang opened a new issue, #14936:
URL: https://github.com/apache/gravitino/issues/14936

   ### Version
   
   main branch
   
   ### Describe what's wrong
   
   When a catalog is created, `CatalogManager.initCatalogWrapper` runs the 
catalog's create-time validation inside the catalog class loader. Only 
`IllegalArgumentException` and `ConnectionFailedException` are passed through 
unchanged. Every other exception is wrapped in a plain `RuntimeException` and 
the REST API returns 500.
   
   A backend that refuses the credentials configured for the catalog (for 
example a cloud account that lacks the permission needed to run statements) is 
a caller-side configuration problem, not an unreachable backend and not an 
internal error. Catalog implementations already have `ForbiddenException` (HTTP 
403) for this, and the catalog REST exception handler already maps it to 403. 
But when it is thrown by the create-time validation, it never reaches that 
handler. A catalog implementation can only choose between two wrong answers: 
502 (`ConnectionFailedException`, which clients treat as "retry later") or 500.
   
   The standalone connection test does not have this problem: it rethrows 
`GravitinoRuntimeException`, so the same denial is reported as 403 there, while 
creating the catalog with the same properties reports 502 or 500.
   
   ### Error message and/or stacktrace
   
   A create-time validation that throws `ForbiddenException` ends up as:
   
   ```
   java.lang.RuntimeException: 
org.apache.gravitino.exceptions.ForbiddenException: <message from the catalog>
        at 
org.apache.gravitino.utils.IsolatedClassLoader.withClassLoader(IsolatedClassLoader.java)
        at 
org.apache.gravitino.catalog.CatalogManager.initCatalogWrapper(CatalogManager.java)
   ```
   
   ### How to reproduce
   
   1. Use a catalog whose `validateOnCreate()` throws `ForbiddenException` (the 
unit test added with the fix does this with the test catalog).
   2. Call `CatalogManager.createCatalog(...)` or `POST 
/api/metalakes/{metalake}/catalogs`.
   3. Observe a `RuntimeException` / HTTP 500 instead of `ForbiddenException` / 
HTTP 403.
   
   ### Additional context
   
   Proposed fix: add `ForbiddenException` to the exceptions that 
`initCatalogWrapper` passes through. This only changes the outcome for 
exceptions that were previously wrapped into a 500. The existing 400 and 502 
results are unchanged, and the failure cleanup (closing the partially created 
catalog, rolling back the entity) is the same for every exception type.
   


-- 
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]

Reply via email to