This is an automated email from the ASF dual-hosted git repository.
laskoviymishka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new e8f7922c8 fix(catalog/rest): map 406 to ErrNotImplemented (#2588)
e8f7922c8 is described below
commit e8f7922c889458a64f325e04193f6557c6979249
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Mon Nov 16 08:49:08 2026 +0100
fix(catalog/rest): map 406 to ErrNotImplemented (#2588)
406 is the spec's UnsupportedOperationResponse, and the reference server
sends it for an UnsupportedOperationException, but the client surfaced it as
a generic REST error while 501 already maps to ErrNotImplemented.
---
catalog/rest/rest.go | 11 +++++++++--
catalog/rest/rest_test.go | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/catalog/rest/rest.go b/catalog/rest/rest.go
index 2ba611e86..5889b45d9 100644
--- a/catalog/rest/rest.go
+++ b/catalog/rest/rest.go
@@ -125,6 +125,11 @@ var (
errCommitForbidden = fmt.Errorf("%w: %w", ErrForbidden,
table.ErrCommitRejected)
errCommitNoSuchTable = fmt.Errorf("%w: %w", catalog.ErrNoSuchTable,
table.ErrCommitRejected)
+ // errNotSupported is a 406 or 501. It keeps ErrRESTError, which a 406
+ // matched before it also became iceberg.ErrNotImplemented. A 501 gains
+ // ErrRESTError here, like every other 5xx.
+ errNotSupported = fmt.Errorf("%w: %w", ErrRESTError,
iceberg.ErrNotImplemented)
+
// errNotModified reports a 304 to a request sent with withIfNoneMatch.
errNotModified = errors.New("not modified")
)
@@ -763,8 +768,10 @@ func handleNon200(rsp *http.Response, override
map[int]error, typeOverride map[s
e.wrapping = ErrRESTError
case 419:
e.wrapping = ErrAuthorizationExpired
- case http.StatusNotImplemented:
- e.wrapping = iceberg.ErrNotImplemented
+ case http.StatusNotAcceptable, http.StatusNotImplemented:
+ // 406 is the spec's UnsupportedOperationResponse; 501 is what
a server
+ // without the operation may answer instead. Both are "not
supported".
+ e.wrapping = errNotSupported
case http.StatusServiceUnavailable:
e.wrapping = ErrServiceUnavailable
default:
diff --git a/catalog/rest/rest_test.go b/catalog/rest/rest_test.go
index 6c6437194..53fe9e356 100644
--- a/catalog/rest/rest_test.go
+++ b/catalog/rest/rest_test.go
@@ -4986,3 +4986,40 @@ func
TestUpdateTableKeepsOnlyCatalogScanPlanningDirective(t *testing.T) {
})
}
}
+
+// TestUnsupportedOperationStatusesAreNotImplemented: 406, the spec's
+// UnsupportedOperationResponse, and 501 both mean the server does not support
+// the operation, so both surface as iceberg.ErrNotImplemented and stay
+// rest.ErrRESTError.
+func TestUnsupportedOperationStatusesAreNotImplemented(t *testing.T) {
+ for _, status := range []int{http.StatusNotAcceptable,
http.StatusNotImplemented} {
+ t.Run(http.StatusText(status), func(t *testing.T) {
+ mux := http.NewServeMux()
+ mux.HandleFunc("/v1/config", func(w
http.ResponseWriter, req *http.Request) {
+ json.NewEncoder(w).Encode(map[string]any{
+ "defaults": map[string]any{},
"overrides": map[string]any{},
+ "endpoints": []string{"POST
/v1/{prefix}/namespaces"},
+ })
+ })
+ mux.HandleFunc("/v1/namespaces", func(w
http.ResponseWriter, req *http.Request) {
+ w.Header().Set("Content-Type",
"application/json")
+ w.WriteHeader(status)
+
json.NewEncoder(w).Encode(map[string]any{"error": map[string]any{
+ "message": "Cannot create namespace ns:
metadata is not supported",
+ "type":
"UnsupportedOperationException",
+ "code": status,
+ }})
+ })
+ srv := httptest.NewServer(mux)
+ defer srv.Close()
+
+ cat, err := rest.NewCatalog(context.Background(),
"rest", srv.URL, rest.WithOAuthToken(TestToken))
+ require.NoError(t, err)
+
+ err = cat.CreateNamespace(context.Background(),
table.Identifier{"ns"}, iceberg.Properties{"owner": "x"})
+ require.ErrorIs(t, err, iceberg.ErrNotImplemented)
+ assert.ErrorIs(t, err, rest.ErrRESTError)
+ assert.ErrorContains(t, err, "metadata is not
supported")
+ })
+ }
+}