Skip to content

Commit 128cec0

Browse files
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 <noreply@anthropic.com>
1 parent 0b7d209 commit 128cec0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ func (c *conn) handleStagingRemove(ctx context.Context, presignedUrl string, hea
529529
content, err := io.ReadAll(res.Body)
530530

531531
if err != nil || !Succeeded(res) {
532-
return dbsqlerrint.NewDriverError(ctx, fmt.Sprintf("staging operation over HTTP was unsuccessful: %d-%s, nil", res.StatusCode, content), nil)
532+
return dbsqlerrint.NewDriverError(ctx, fmt.Sprintf("staging operation over HTTP was unsuccessful: %d-%s", res.StatusCode, content), nil)
533533
}
534534

535535
return nil

staging_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
package dbsql
22

33
import (
4+
"context"
5+
"net/http"
6+
"net/http/httptest"
47
"testing"
58

9+
"github.com/databricks/databricks-sql-go/internal/config"
610
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
712
)
813

14+
func TestHandleStagingRemoveHTTPError(t *testing.T) {
15+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
16+
w.WriteHeader(http.StatusForbidden)
17+
w.Write([]byte("Access Denied"))
18+
}))
19+
defer server.Close()
20+
21+
c := &conn{cfg: config.WithDefaults()}
22+
err := c.handleStagingRemove(context.Background(), server.URL, map[string]string{})
23+
require.NotNil(t, err)
24+
assert.NotContains(t, err.Error(), ", nil", "error message should not contain literal \", nil\"")
25+
}
26+
927
func TestPathAllowed(t *testing.T) {
1028
t.Run("Should not allow paths that don't share directory", func(t *testing.T) {
1129
stagingAllowedLocalPath := []string{"/var/www/html"}

0 commit comments

Comments
 (0)