Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,26 @@ version: "2"
linters:
default: none
enable:
- errcheck
- misspell
- nlreturn
- perfsprint
settings:
errcheck:
exclude-functions:
- (github.com/pterm/pterm.TablePrinter).Render
- (github.com/pterm/pterm.TreePrinter).Render
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- errcheck
path: _test\.go$
paths:
- third_party$
- builtin$
Expand Down
18 changes: 13 additions & 5 deletions catalog/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,15 @@ func doPostAllowNoContent[Payload, Result any](ctx context.Context, baseURI *url
func handleNon200(rsp *http.Response, override map[int]error) error {
var e errorResponse

dec := json.NewDecoder(rsp.Body)
dec.Decode(&struct {
Error *errorResponse `json:"error"`
}{Error: &e})
// Only try to decode if there's a body (HEAD requests don't have one)
if rsp.ContentLength != 0 {
decErr := json.NewDecoder(rsp.Body).Decode(&struct {
Error *errorResponse `json:"error"`
}{Error: &e})
if decErr != nil && decErr != io.EOF {
return fmt.Errorf("%w: failed to decode error response: %s", ErrRESTError, decErr.Error())
}
}

if override != nil {
if err, ok := override[rsp.StatusCode]; ok {
Expand Down Expand Up @@ -569,7 +574,10 @@ func (r *Catalog) fetchAccessToken(cl *http.Client, creds string, opts *options)

switch rsp.StatusCode {
case http.StatusUnauthorized, http.StatusBadRequest:
defer rsp.Request.GetBody()
defer func() {
_, _ = io.Copy(io.Discard, rsp.Body)
_ = rsp.Body.Close()
}()
dec := json.NewDecoder(rsp.Body)
var oauthErr oauthErrorResponse
if err := dec.Decode(&oauthErr); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion catalog/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ type sqlIcebergNamespaceProps struct {
}

func withReadTx[R any](ctx context.Context, db *bun.DB, fn func(context.Context, bun.Tx) (R, error)) (result R, err error) {
db.RunInTx(ctx, &sql.TxOptions{ReadOnly: true}, func(ctx context.Context, tx bun.Tx) error {
err = db.RunInTx(ctx, &sql.TxOptions{ReadOnly: true}, func(ctx context.Context, tx bun.Tx) error {
result, err = fn(ctx, tx)

return err
Expand Down
4 changes: 3 additions & 1 deletion manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,9 @@ func constructPartitionSummaries(spec PartitionSpec, schema *Schema, partitions

for _, part := range partitions {
for i, field := range partType.FieldList {
fieldStats[i].update(part[field.ID])
if err := fieldStats[i].update(part[field.ID]); err != nil {
return nil, fmt.Errorf("error updating field stats for partition %d: %s: %s", i, field.Name, err)
}
}
}

Expand Down
Loading