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 94d9ecfb9 fix(hive): preserve RegisterTable creation errors (#1573)
94d9ecfb9 is described below

commit 94d9ecfb9a6598bf40172f93dc5539237f258e68
Author: Minh Vu <[email protected]>
AuthorDate: Tue Aug 4 12:31:46 2026 +0200

    fix(hive): preserve RegisterTable creation errors (#1573)
    
    ## What changed
    
    Wrap the Hive metastore `CreateTable` failure returned by
    `RegisterTable` with `%w`.
    
    ## Why
    
    The previous `%s` formatting converted the cause to text, preventing
    callers from detecting context, transport, or typed metastore errors
    with `errors.Is` and `errors.As`.
    
    The regression test verifies that the original creation error remains
    discoverable.
    
    ## Testing
    
    - `go test ./catalog/hive`
    - `go vet ./catalog/hive`
    
    ---------
    
    Signed-off-by: Minh Vu <[email protected]>
---
 catalog/hive/hive.go      |  2 +-
 catalog/hive/hive_test.go | 31 +++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/catalog/hive/hive.go b/catalog/hive/hive.go
index 3e108c1e1..1c916a3cc 100644
--- a/catalog/hive/hive.go
+++ b/catalog/hive/hive.go
@@ -293,7 +293,7 @@ func (c *Catalog) RegisterTable(ctx context.Context, 
identifier table.Identifier
                        return nil, fmt.Errorf("%w: %s.%s", 
catalog.ErrTableAlreadyExists, database, tableName)
                }
 
-               return nil, fmt.Errorf("failed to register table %s.%s: %s", 
database, tableName, err)
+               return nil, fmt.Errorf("failed to register table %s.%s: %w", 
database, tableName, err)
        }
 
        return c.LoadTable(ctx, identifier)
diff --git a/catalog/hive/hive_test.go b/catalog/hive/hive_test.go
index d741a9566..734feeaa8 100644
--- a/catalog/hive/hive_test.go
+++ b/catalog/hive/hive_test.go
@@ -1370,6 +1370,37 @@ func TestHiveRegisterTableSuccess(t *testing.T) {
        mockClient.AssertExpectations(t)
 }
 
+func TestHiveRegisterTablePreservesCreateError(t *testing.T) {
+       metaPath, err := filepath.Abs(filepath.Join("..", "..", "table", 
"testdata", "TableMetadataV2Valid.json"))
+       require.NoError(t, err)
+
+       tests := []struct {
+               name      string
+               createErr error
+       }{
+               {name: "metastore failure", createErr: errors.New("metastore 
unavailable")},
+               {name: "canceled context", createErr: context.Canceled},
+       }
+
+       for _, test := range tests {
+               t.Run(test.name, func(t *testing.T) {
+                       mockClient := &mockHiveClient{}
+                       mockClient.On("GetDatabase", mock.Anything, 
"test_database").
+                               Return(&hive_metastore.Database{Name: 
"test_database"}, nil).Once()
+                       mockClient.On("GetTable", mock.Anything, 
"test_database", "reg_table").
+                               Return(nil, errNoSuchObject).Times(2)
+                       mockClient.On("CreateTable", mock.Anything, 
mock.AnythingOfType("*hive_metastore.Table")).
+                               Return(test.createErr).Once()
+
+                       hiveCatalog := NewCatalogWithClient(mockClient, 
iceberg.Properties{})
+                       _, err := 
hiveCatalog.RegisterTable(context.Background(), 
TableIdentifier("test_database", "reg_table"), metaPath)
+                       require.ErrorContains(t, err, "failed to register table 
test_database.reg_table")
+                       require.ErrorIs(t, err, test.createErr)
+                       mockClient.AssertExpectations(t)
+               })
+       }
+}
+
 func TestHiveCheckViewExists(t *testing.T) {
        assert := require.New(t)
 

Reply via email to