-
Notifications
You must be signed in to change notification settings - Fork 935
[#12975] fix(core): Preserve errors thrown by PrincipalUtils.doAs #12976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jerryshao
merged 5 commits into
apache:main
from
qqqttt123:fix/principal-utils-propagate-error
Sep 10, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9966cdb
[#12975] fix(core): Preserve errors thrown by PrincipalUtils.doAs
roryqi 9f250eb
[#12975] test(server): Align with Error propagation
roryqi 6b22c32
[#12975] fix(server): Preserve request error diagnostics in REST resp…
roryqi a28bc42
[#12975] fix(iceberg): Preserve request error diagnostics in REST res…
roryqi 13e0eaa
[#12975] fix(lance): Preserve errors in REST responses
roryqi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...t-server/src/test/java/org/apache/gravitino/iceberg/service/TestIcebergErrorHandling.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.gravitino.iceberg.service; | ||
|
|
||
| import java.io.IOException; | ||
| import javax.ws.rs.GET; | ||
| import javax.ws.rs.Path; | ||
| import javax.ws.rs.PathParam; | ||
| import javax.ws.rs.core.Application; | ||
| import javax.ws.rs.core.MediaType; | ||
| import javax.ws.rs.core.Response; | ||
| import org.apache.gravitino.UserPrincipal; | ||
| import org.apache.gravitino.rest.RESTUtils; | ||
| import org.apache.gravitino.utils.PrincipalUtils; | ||
| import org.apache.iceberg.rest.responses.ErrorResponse; | ||
| import org.glassfish.jersey.jackson.JacksonFeature; | ||
| import org.glassfish.jersey.server.ResourceConfig; | ||
| import org.glassfish.jersey.test.JerseyTest; | ||
| import org.glassfish.jersey.test.TestProperties; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** Tests Iceberg HTTP responses for errors raised on the request path. */ | ||
| public class TestIcebergErrorHandling extends JerseyTest { | ||
|
|
||
| /** Simulates direct failures and failures inside the REST doAs boundary. */ | ||
| @Path("failure") | ||
| public static class FailureResource { | ||
|
|
||
| /** | ||
| * Executes a request with an optional failure. | ||
| * | ||
| * @param mode whether to fail directly, within doAs, or return a successful response | ||
| * @return the request response | ||
| */ | ||
| @GET | ||
| @Path("{mode}") | ||
| public Response request(@PathParam("mode") String mode) { | ||
| if ("healthy".equals(mode)) { | ||
| return Response.ok().build(); | ||
| } | ||
| Error failure = new NoClassDefFoundError("catalog class"); | ||
| failure.initCause(new ClassNotFoundException("missing dependency")); | ||
| if ("direct".equals(mode)) { | ||
| throw failure; | ||
| } | ||
| try { | ||
| return PrincipalUtils.doAs( | ||
| new UserPrincipal("test"), | ||
| () -> { | ||
| throw failure; | ||
| }); | ||
| } catch (Exception e) { | ||
| return IcebergExceptionMapper.toRESTResponse(e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Registers the same error and JSON mappers as the Iceberg REST service. | ||
| * | ||
| * @return the test application | ||
| */ | ||
| @Override | ||
| protected Application configure() { | ||
| try { | ||
| forceSet( | ||
| TestProperties.CONTAINER_PORT, String.valueOf(RESTUtils.findAvailablePort(2000, 3000))); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| return new ResourceConfig() | ||
| .register(FailureResource.class) | ||
| .register(IcebergExceptionMapper.class) | ||
| .register(IcebergObjectMapperProvider.class) | ||
| .register(JacksonFeature.class); | ||
| } | ||
|
|
||
| /** | ||
| * Verifies diagnostics survive both request paths and later requests can still succeed. | ||
| * | ||
| * @throws IOException if the JSON response cannot be parsed | ||
| */ | ||
| @Test | ||
| public void testErrorResponsesAndSubsequentRequests() throws IOException { | ||
| for (String mode : new String[] {"direct", "do-as"}) { | ||
| try (Response response = | ||
| target("failure/" + mode).request(MediaType.APPLICATION_JSON_TYPE).get()) { | ||
| Assertions.assertEquals(500, response.getStatus()); | ||
| Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getMediaType()); | ||
| ErrorResponse error = | ||
| IcebergObjectMapper.getInstance() | ||
| .readValue(response.readEntity(String.class), ErrorResponse.class); | ||
| Assertions.assertEquals(500, error.code()); | ||
| Assertions.assertEquals("NoClassDefFoundError", error.type()); | ||
| Assertions.assertEquals("catalog class", error.message()); | ||
| Assertions.assertTrue( | ||
| String.join("\n", error.stack()) | ||
| .contains("Caused by: java.lang.ClassNotFoundException: missing dependency")); | ||
| } | ||
| try (Response response = target("failure/healthy").request().get()) { | ||
| Assertions.assertEquals(200, response.getStatus()); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will be the exception when propogating to the client side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current behavior is the server will crash.