Repository navigation
[Server] Type Iceberg REST errors in Iceberg's vocabulary - #1797
Conversation
d996468 to
e45a359
Compare
|
Please rebase. The conflict was caused by #1696. |
e45a359 to
a49445a
Compare
|
Rebased onto #1696 landed in the same file and already names four codes -- This PR sits on top of that work rather than replacing it. Two things changed while re-reviewing the rebase:
The commit message describes the remaining gap rather than the original one. |
a49445a to
636348b
Compare
| } | ||
|
|
||
| @Test | ||
| public void testErrorsAreNamedInIcebergTerms() |
There was a problem hiding this comment.
Existing test already assert on failures like this:
// not setting warehouse param should result in 400 BadRequestException
resp = client.get("/v1/config").aggregate().join();
assertThat(resp.status().code()).isEqualTo(400);
Can you replace them with assertErrorType instead of adding a separate test?
There was a problem hiding this comment.
Done. The separate test is gone; its cases now sit with the endpoints they belong to, and assertErrorType replaced the bare status assertions as well as the three places that spelled out the same two assertions by hand. Three cases had no existing home, so they went into testNamespaces: a catalog that does not exist, a schema that does not exist, and the dotted name a nested namespace arrives as.
The coverage got stronger rather than just shorter -- on an unfixed tree testTable, testNamespaces and testReportMetrics now fail with "expected BadRequestException but was BaseException" / "was IllegalArgumentException".
| ErrorCode.ALREADY_EXISTS, | ||
| baseException.getErrorMessage(), | ||
| new CommitFailedException("%s", baseException.getErrorMessage())); | ||
| new BaseException(ErrorCode.ALREADY_EXISTS, baseException.getErrorMessage()); |
There was a problem hiding this comment.
Use wrapException(ErrorCode.ALREADY_EXISTS, baseException.getErrorMessage(), baseException); to keep the original stack trace.
This was missed in some lines here before this PR. But please fix it.
IcebergRestExceptionHandler names the error type after the original exception's Java class, which is right for an exception Iceberg raised. Unity Catalog's own BaseException is not one, and when it is thrown directly it has no cause for getOriginalException to walk to, so it goes out as "type": "BaseException". which also moves the two already-exists codes off their legacy 400. The codes its switch does not name still reach the client as "BaseException": verified on this commit's parent, a catalog that does not exist answers 404 "type": "BaseException", and a namespace name Unity Catalog rejects -- the dotted name a nested namespace arrives as -- answers 400 "type": "BaseException". Iceberg's client switches on that field. ErrorHandlers.TableErrorHandler raises NoSuchNamespaceException on a 404 only when the type names it, and NoSuchTableException otherwise, so a missing catalog came back to the client as a missing table. Name every error that is still a BaseException from its error code, mapping each code to the Iceberg exception the client raises for that code's HTTP status. The switch over ErrorCode is exhaustive, so a code added later has to name its Iceberg counterpart rather than silently inherit "BaseException". Exceptions that did not come from Unity Catalog, including the ones unitycatalog#1696 wraps, keep naming themselves, so the errors Iceberg raises are unaffected. Statuses and messages are unchanged. A request Iceberg's own parsers reject is named too. They raise IllegalArgumentException, which the base handler already answers 400 for and whose message is already in Iceberg's terms, but whose class name means nothing to a client; it is reported as BadRequestException, with the original failure kept underneath it. Signed-off-by: Noritaka Sekiyama <[email protected]>
Review follow-up. errorType keys on the exception's package rather than on whether it is still a BaseException, so an exception raised by a library Unity Catalog happens to call is named from the error code as well, instead of reaching the client as its own class name. That leaves toBaseException with less to do. SCHEMA_NOT_FOUND and TABLE_NOT_FOUND already carry 404, and UPDATE_REQUIREMENT_CONFLICT already carries 409 with CommitFailedException as its code's name, so re-raising those three as Iceberg exceptions only supplied names the code now supplies -- as did rewrapping the IllegalArgumentException Iceberg's own parsers raise, which the base handler already answers 400 for. What stays is the one thing naming cannot do: the two legacy already-exists codes answer 400 on the native REST surface, which no Iceberg client reads as a conflict, so they are still re-raised as ALREADY_EXISTS for its 409. The test that collected these cases is gone. They now sit with the endpoints they belong to, asserted with assertErrorType in place of the bare status checks those tests carried, so the same cases are covered where a reader of each endpoint's test will see them. Signed-off-by: Noritaka Sekiyama <[email protected]>
The two legacy already-exists codes are re-raised to carry the status an Iceberg client reads as a conflict. Building a fresh BaseException dropped the original exception, and with it the stack trace the error log reports; wrapException keeps it as the cause and clears its own trace so getRelevantStackTrace falls back to the original one. Signed-off-by: Noritaka Sekiyama <[email protected]>
71af91a to
f64da52
Compare
|
Done -- I checked the rest of the file for the same omission you mentioned: the three |
…or-types # Conflicts: # server/src/test/java/io/unitycatalog/server/service/IcebergRestCatalogTest.java
PR Checklist
docsis updatedDescription of changes
Fixes #1796.
IcebergRestExceptionHandlernames the error type after the original exception's Java class. For an exception Iceberg raised that is exactly right, andgetOriginalExceptionwalks the cause chain so a wrapped one still names itself. Unity Catalog's ownBaseExceptionis neither: it is not an Iceberg exception, and when it is thrown directly it has no cause to walk to, so the walk returns the wrapper and every error that starts in Unity Catalog code -- a catalog, schema, or table that does not exist, a name that fails validation -- went out as"type": "BaseException".Iceberg's client switches on that field.
ErrorHandlers.TableErrorHandlerraisesNoSuchNamespaceExceptionon a 404 only when the type names it, andNoSuchTableExceptionotherwise, so a request for a table in a schema that does not exist came back to the client as a missing table.Name those errors from their error code instead, mapping each code to the Iceberg exception the client raises for that code's HTTP status. Exceptions that did not come from Unity Catalog keep naming themselves, so nothing changes for the errors Iceberg raises. The mapping is an exhaustive switch, so a new error code has to name its Iceberg counterpart rather than silently inherit a misleading one.
typebeforetypeafterGET /namespaces(catalog missing)BaseExceptionNoSuchNamespaceExceptionGET /namespaces/{ns}(schema missing)BaseExceptionNoSuchNamespaceExceptionGET /namespaces/{ns}/tables(schema missing)BaseExceptionNoSuchNamespaceExceptionGET /namespaces/{ns}/tables/{table}(schema missing)BaseExceptionNoSuchNamespaceExceptionGET /namespaces/{ns}/tables/{table}(table missing)BaseExceptionNoSuchTableExceptionPOST /namespaces/{ns}/tables/{table}/metrics(table missing)BaseExceptionNoSuchTableExceptionGET /namespaces/{ns}(multi-level name)BaseExceptionBadRequestExceptionGET /namespaces/{ns}/tables/{table}(no Iceberg metadata)NoSuchTableExceptionNoSuchTableExceptionStatuses and messages are untouched, so a client that reads only those sees no change.
Verified against a running server with Iceberg's own
RESTCatalog1.11.0:loadTableon a table in a schema that does not exist raisedNoSuchTableException: Schema not found: ...before this change and raisesNoSuchNamespaceException: Schema not found: ...after it. The new test fails onmainand passes with the fix; the rest of the Iceberg suite is unchanged.