Skip to content

[Server] Test every ErrorCode's response on UC REST, Iceberg and Delta - #2049

Merged
yili-db merged 1 commit into
unitycatalog:mainfrom
NopeCharon:map-error-code-responses
Oct 26, 2026
Merged

yili-db merged 1 commit into
unitycatalog:mainfrom
NopeCharon:map-error-code-responses

Conversation

@NopeCharon

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 (not needed, test-only change)

Description of changes

Closes #2043.

#2008 added per-handler assertions to ManagedTableCleanupTaskTest.dropBlockedByCommitLockIsUnavailable for how one error code (UNAVAILABLE) reaches clients on each API. This PR replaces those with a single test that pins the response for every ErrorCode on all three APIs.

Changes:

  • New server/src/test/java/io/unitycatalog/server/exception/ErrorCodeTest. It runs every ErrorCode (@EnumSource) through GlobalExceptionHandler, IcebergRestExceptionHandler and DeltaApiExceptionHandler, and checks:
    • UC REST: the HTTP status and error_code
    • Iceberg REST: the HTTP status, plus the ErrorResponse code and type
    • Delta: the HTTP status, plus error.code and error.type
  • The expected responses come from an exhaustive switch over ErrorCode. A new error code therefore won't compile until its responses on all three APIs are written down, and changing any existing mapping fails the test. The table also documents the intended differences between the APIs:
    • the legacy *_ALREADY_EXISTS codes are 400 on UC REST and 409 on Delta. On Iceberg, SCHEMA_ALREADY_EXISTS and TABLE_ALREADY_EXISTS are 409, and the other legacy codes are 400.
    • UNPROCESSABLE_ENTITY is 422 on Iceberg and 400 (InvalidParameterValueException) on Delta.
  • dropBlockedByCommitLockIsUnavailable drops its per-handler assertions and the errorResponse helper. It still checks that the drop fails as UNAVAILABLE.

No production code changes.

Tests:

  • build/sbt "server/javafmtCheckAll" "server/testOnly io.unitycatalog.server.exception.ErrorCodeTest io.unitycatalog.server.persist.ManagedTableCleanupTaskTest": 27 + 7 tests passed, format check clean.
  • As a sanity check I changed UNAVAILABLE to 500 in ErrorCode. ErrorCodeTest then failed for that code (expected: 503). I reverted the change.

Add ErrorCodeTest, which runs every ErrorCode through the three exception
handlers (GlobalExceptionHandler, IcebergRestExceptionHandler and
DeltaApiExceptionHandler) and checks the HTTP status, the status echoed
in the body and the error type each one returns:

- UC REST: status and error_code
- Iceberg REST: status, ErrorResponse code and type
- Delta: status, error.code and error.type

The expected responses come from an exhaustive switch over ErrorCode, so
a new error code does not compile until its responses on all three APIs
are written down, and a change to any existing mapping fails the test.
The table also pins the deliberate differences between the APIs: the
legacy *_ALREADY_EXISTS codes answer 400 on UC REST but 409 on Delta (and
on Iceberg for schema and table), and UNPROCESSABLE_ENTITY is a 422 on
Iceberg but a 400 on Delta.

With the mapping covered in one place, drop the per-handler assertions
from ManagedTableCleanupTaskTest.dropBlockedByCommitLockIsUnavailable.
It still checks that the drop fails as UNAVAILABLE, and ErrorCodeTest
covers how each API reports that code.

Closes unitycatalog#2043

Signed-off-by: NopeCharon <[email protected]>
@yili-db

yili-db commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db
yili-db merged commit 88d442d into unitycatalog:main Oct 26, 2026
18 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.

Map every ErrorCode to its status on UC REST, Iceberg and Delta

2 participants