From 9c4f2cbe2b2ffb78251977279b4a7c83a6b1a989 Mon Sep 17 00:00:00 2001 From: Tauseef Date: Fri, 27 Mar 2026 23:41:39 -0500 Subject: [PATCH] Fix literal \", nil\" in handleStagingRemove error format string The format string in handleStagingRemove mistakenly included ", nil" as literal text instead of keeping it outside the Sprintf call, causing every HTTP failure error message to end with ", nil". Adds a regression test using httptest to verify the error message is clean on a simulated 403 response. Co-Authored-By: Claude Sonnet 4.6 --- connection.go | 2 +- staging_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/connection.go b/connection.go index 01e5e8cb..3911289c 100644 --- a/connection.go +++ b/connection.go @@ -587,7 +587,7 @@ func (c *conn) handleStagingRemove(ctx context.Context, presignedUrl string, hea content, err := io.ReadAll(res.Body) if err != nil || !Succeeded(res) { - return dbsqlerrint.NewDriverError(ctx, fmt.Sprintf("staging operation over HTTP was unsuccessful: %d-%s, nil", res.StatusCode, content), nil) + return dbsqlerrint.NewDriverError(ctx, fmt.Sprintf("staging operation over HTTP was unsuccessful: %d-%s", res.StatusCode, content), nil) } return nil diff --git a/staging_test.go b/staging_test.go index 13cc5c9b..731aa1ca 100644 --- a/staging_test.go +++ b/staging_test.go @@ -1,11 +1,29 @@ package dbsql import ( + "context" + "net/http" + "net/http/httptest" "testing" + "github.com/databricks/databricks-sql-go/internal/config" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) +func TestHandleStagingRemoveHTTPError(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusForbidden) + w.Write([]byte("Access Denied")) + })) + defer server.Close() + + c := &conn{cfg: config.WithDefaults()} + err := c.handleStagingRemove(context.Background(), server.URL, map[string]string{}) + require.NotNil(t, err) + assert.NotContains(t, err.Error(), ", nil", "error message should not contain literal \", nil\"") +} + func TestPathAllowed(t *testing.T) { t.Run("Should not allow paths that don't share directory", func(t *testing.T) { stagingAllowedLocalPath := []string{"/var/www/html"}