Repository navigation
[Server] Return a general error when the server's storage or STS calls fail #2176
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
Changes from all commits
b5c84c7
78b52bb
c071025
1797780
69506e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package io.unitycatalog.server.exception; | ||
|
|
||
| import software.amazon.awssdk.core.exception.SdkException; | ||
|
|
||
| /** | ||
| * Failures of the server's own AWS SDK calls, such as to S3. Their messages, from the SDK or the | ||
| * storage service, can name its endpoint, so callers get a general error. The failure is kept as | ||
| * the cause, for the caller to log. Azure and GCS failures are not covered. | ||
| */ | ||
| public final class StorageExceptions { | ||
| /** The message callers get when the server's storage access fails. */ | ||
| private static final String GENERAL_MESSAGE = "Failed to access storage."; | ||
|
|
||
| // Bounds the walk over causes, which a cycle would otherwise make endless. | ||
| private static final int MAX_CAUSE_DEPTH = 64; | ||
|
|
||
| private StorageExceptions() {} | ||
|
|
||
| /** | ||
| * Whether {@code e} or one of its causes is an AWS SDK failure. The walk stops at a {@link | ||
| * BaseException}, which already says what callers get. | ||
| */ | ||
| public static boolean isStorageFailure(Throwable e) { | ||
| Throwable current = e; | ||
| for (int depth = 0; current != null && depth < MAX_CAUSE_DEPTH; depth++) { | ||
| if (current instanceof SdkException) { | ||
| return true; | ||
| } | ||
| if (current instanceof BaseException) { | ||
| return false; | ||
| } | ||
| current = current.getCause(); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the general error reported for a storage failure. | ||
| * | ||
| * @param e a failure for which {@link #isStorageFailure} holds | ||
| * @return an INTERNAL error that carries no storage detail in its message | ||
| */ | ||
| public static BaseException toGeneralError(Throwable e) { | ||
| return BaseExceptionHandler.wrapException(ErrorCode.INTERNAL, GENERAL_MESSAGE, e); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,8 @@ | |||||||
| import io.unitycatalog.server.testdatabase.SupportedDatabase; | ||||||||
| import io.unitycatalog.server.testdatabase.TempDatabase; | ||||||||
| import io.unitycatalog.server.testdatabase.TestDatabase; | ||||||||
| import java.io.IOException; | ||||||||
| import java.io.UncheckedIOException; | ||||||||
| import java.sql.Connection; | ||||||||
| import java.sql.SQLException; | ||||||||
| import java.util.Date; | ||||||||
|
|
@@ -51,6 +53,7 @@ | |||||||
| import org.junit.jupiter.params.provider.MethodSource; | ||||||||
| import org.mockito.Mock; | ||||||||
| import org.mockito.junit.jupiter.MockitoExtension; | ||||||||
| import software.amazon.awssdk.core.exception.SdkClientException; | ||||||||
|
|
||||||||
| public class TransactionManagerTest { | ||||||||
|
|
||||||||
|
|
@@ -145,6 +148,31 @@ public void testTransactionWithRuntimeException() { | |||||||
| verify(transaction, never()).commit(); | ||||||||
| } | ||||||||
|
|
||||||||
| @Test | ||||||||
| public void testStorageFailureReportsGeneralError() { | ||||||||
| // Storage messages name the storage endpoint, so only the general error is reported. | ||||||||
| RuntimeException storageFailure = | ||||||||
| new UncheckedIOException( | ||||||||
| new IOException( | ||||||||
| SdkClientException.create("Connect to storage.example.com:9000 failed"))); | ||||||||
|
|
||||||||
| assertThatThrownBy( | ||||||||
| () -> | ||||||||
| TransactionManager.executeWithTransaction( | ||||||||
| sessionFactory, | ||||||||
| session -> { | ||||||||
| throw storageFailure; | ||||||||
| }, | ||||||||
| "Error executing operation", | ||||||||
| false)) | ||||||||
| .isInstanceOf(BaseException.class) | ||||||||
| .hasMessage("Failed to access storage.") | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this also check that the storage failure is kept as the cause? On this path the handler logs the general
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||||||||
| .hasCause(storageFailure) | ||||||||
| .extracting(e -> ((BaseException) e).getErrorCode()) | ||||||||
| .isEqualTo(ErrorCode.INTERNAL); | ||||||||
| verify(transaction).rollback(); | ||||||||
| } | ||||||||
|
|
||||||||
| @Test | ||||||||
| public void testTransactionRollbackExceptionIsRethrownAsIsNotWrapped() { | ||||||||
| // A TransactionRollbackException signals rollback, not an error, so it is rethrown by | ||||||||
|
|
||||||||
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.
an IllegalArgumentException can wrap an SDK error.