Skip to content

Commit 06b4272

Browse files
authored
apierr: Alias ErrResourceAlreadyExists to ErrAlreadyExists (#1639)
## Changes `apierr` defined two 409 sentinels with identical messages but distinct pointers: - `ErrAlreadyExists` &mdash; mapped from `error_code: ALREADY_EXISTS` (gRPC canonical) - `ErrResourceAlreadyExists` &mdash; mapped from `error_code: RESOURCE_ALREADY_EXISTS` (Databricks-specific) Consumers using `errors.Is` with one sentinel did not match errors wrapped with the other, even though both represent the same class of 409 conflict. Which of the two `error_code` strings the backend returns is not guaranteed, so consumers had to either assert the generic `ErrResourceConflict` or duplicate both sentinels in their checks. This came up downstream in databricks/cli#5043 where a `TestDashboardAssumptions_WorkspaceImport` assertion on `ErrResourceAlreadyExists` started failing because the Lakeview API returns `ALREADY_EXISTS` rather than `RESOURCE_ALREADY_EXISTS`. Alias `ErrResourceAlreadyExists` to `ErrAlreadyExists` so `errors.Is` matches either `error_code` regardless of which the backend emits. The exported symbol is preserved, so this is source- and binary-compatible for all existing callers. Also extended `TestErrorMapping` to cover both error_codes against both sentinels and against the shared `ErrResourceConflict` parent. ## Tests - [x] `go test ./apierr/...` passes, including new `RESOURCE_ALREADY_EXISTS` ↔ `ErrAlreadyExists` and `ALREADY_EXISTS` ↔ `ErrResourceAlreadyExists` cases. - [x] `make fmt` clean. - [x] `make lint` clean. Signed-off-by: simon <simon.faltum@databricks.com>
1 parent 7aae318 commit 06b4272

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bug Fixes
1010

11+
* Alias `apierr.ErrResourceAlreadyExists` to `apierr.ErrAlreadyExists` so `errors.Is` matches both the gRPC-canonical `ALREADY_EXISTS` and the Databricks-specific `RESOURCE_ALREADY_EXISTS` error codes, regardless of which one the backend returns.
12+
1113
### Documentation
1214

1315
### Internal Changes

apierr/error_mapping.go

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apierr/unwrap_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ var testTable = []mapping{
1717
codeMapping(409, "ABORTED", ErrAborted),
1818
codeMapping(409, "ABORTED", ErrResourceConflict),
1919
codeMapping(409, "ALREADY_EXISTS", ErrAlreadyExists),
20+
codeMapping(409, "ALREADY_EXISTS", ErrResourceAlreadyExists),
2021
codeMapping(409, "ALREADY_EXISTS", ErrResourceConflict),
22+
codeMapping(409, "RESOURCE_ALREADY_EXISTS", ErrAlreadyExists),
23+
codeMapping(409, "RESOURCE_ALREADY_EXISTS", ErrResourceAlreadyExists),
24+
codeMapping(409, "RESOURCE_ALREADY_EXISTS", ErrResourceConflict),
2125
statusMapping(429, ErrTooManyRequests),
2226
codeMapping(429, "REQUEST_LIMIT_EXCEEDED", ErrTooManyRequests),
2327
codeMapping(429, "REQUEST_LIMIT_EXCEEDED", ErrRequestLimitExceeded),

0 commit comments

Comments
 (0)