Skip to content

[Server] Type Iceberg REST errors in Iceberg's vocabulary - #1797

Merged
yili-db merged 4 commits into
unitycatalog:mainfrom
moomindani:fix/iceberg-error-types
Sep 10, 2026
Merged

yili-db merged 4 commits into
unitycatalog:mainfrom
moomindani:fix/iceberg-error-types

Conversation

@moomindani

Copy link
Copy Markdown
Contributor

PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Description of changes

Fixes #1796.

IcebergRestExceptionHandler names the error type after the original exception's Java class. For an exception Iceberg raised that is exactly right, and getOriginalException walks the cause chain so a wrapped one still names itself. Unity Catalog's own BaseException is 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.TableErrorHandler raises NoSuchNamespaceException on a 404 only when the type names it, and NoSuchTableException otherwise, 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.

request status type before type after
GET /namespaces (catalog missing) 404 BaseException NoSuchNamespaceException
GET /namespaces/{ns} (schema missing) 404 BaseException NoSuchNamespaceException
GET /namespaces/{ns}/tables (schema missing) 404 BaseException NoSuchNamespaceException
GET /namespaces/{ns}/tables/{table} (schema missing) 404 BaseException NoSuchNamespaceException
GET /namespaces/{ns}/tables/{table} (table missing) 404 BaseException NoSuchTableException
POST /namespaces/{ns}/tables/{table}/metrics (table missing) 404 BaseException NoSuchTableException
GET /namespaces/{ns} (multi-level name) 400 BaseException BadRequestException
GET /namespaces/{ns}/tables/{table} (no Iceberg metadata) 404 NoSuchTableException NoSuchTableException

Statuses and messages are untouched, so a client that reads only those sees no change.

Verified against a running server with Iceberg's own RESTCatalog 1.11.0: loadTable on a table in a schema that does not exist raised NoSuchTableException: Schema not found: ... before this change and raises NoSuchNamespaceException: Schema not found: ... after it. The new test fails on main and passes with the fix; the rest of the Iceberg suite is unchanged.

@moomindani
moomindani force-pushed the fix/iceberg-error-types branch from d996468 to e45a359 Compare August 21, 2026 09:47
@yili-db

yili-db commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Please rebase. The conflict was caused by #1696.

@moomindani
moomindani force-pushed the fix/iceberg-error-types branch from e45a359 to a49445a Compare September 5, 2026 12:50
@moomindani

moomindani commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased onto 58d5c7b (main), and reviewed again on top of that rebase.

#1696 landed in the same file and already names four codes -- SCHEMA_NOT_FOUND, TABLE_NOT_FOUND, the already-exists pair, and UPDATE_REQUIREMENT_CONFLICT -- by wrapping them in the Iceberg exception that stands for them, so the schema and table cases from #1796 are fixed on main. What its default -> baseException leaves is still untyped: measured on 58d5c7b, GET /v1/catalogs/noSuchCatalog/namespaces answers 404 "type": "BaseException" and GET .../namespaces/nested.namespace answers 400 "type": "BaseException".

This PR sits on top of that work rather than replacing it. toBaseException keeps #1696's switch, which is what moves the already-exists codes off their legacy 400, and the error type is named from the error code only for exceptions that reach createErrorResponse still being a BaseException. The javadoc now states that division of labour so the two are not read as duplicates. The switch over ErrorCode is exhaustive, so a code added later has to name its Iceberg counterpart instead of silently inheriting BaseException; COMMIT_STATE_UNKNOWN, added since I opened this, is mapped to ServiceFailureException for its 500.

Two things changed while re-reviewing the rebase:

  • ABORTED no longer names CommitFailedException. It is the generic abort -- the only callers that raise it are JwksOperations (token verification) and ModelRepository, neither of which is a commit -- so it names RESTException, and only COMMIT_VERSION_CONFLICT and UPDATE_REQUIREMENT_CONFLICT claim a commit failed.
  • A request Iceberg's own parsers reject is now 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: POST .../metrics with {"report-type": {"not": "a string"}} answered 400 "type": "IllegalArgumentException". It now answers BadRequestException, with the original failure kept underneath so the server's own logs still have it.

The commit message describes the remaining gap rather than the original one. testErrorsAreNamedInIcebergTerms covers the missing catalog, the rejected namespace name and the parser rejection; it fails on 58d5c7b at the first of those and passes with the fix. server/testOnly io.unitycatalog.server.service.IcebergRestCatalogTest is green (10/10), and the full server/test suite shows no failure attributable to this change.

}

@Test
public void testErrorsAreNamedInIcebergTerms()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@moomindani
moomindani force-pushed the fix/iceberg-error-types branch from 71af91a to f64da52 Compare September 10, 2026 00:55
@moomindani

Copy link
Copy Markdown
Contributor Author

Done -- wrapException keeps the original exception as the cause, and clears its own trace so getRelevantStackTrace falls back to it. Also rebased onto 4ee2b248; #1799, #1836 and #1847 landing in the same two files is what made this conflict.

I checked the rest of the file for the same omission you mentioned: the three wrapException calls below already pass the cause, so this was the only one.

…or-types

# Conflicts:
#	server/src/test/java/io/unitycatalog/server/service/IcebergRestCatalogTest.java
@yili-db
yili-db merged commit 1f5ebb0 into unitycatalog:main Sep 10, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg REST errors raised by Unity Catalog are typed "BaseException", so clients read a missing namespace as a missing table

2 participants