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
6 changes: 6 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ linters:
- reassign
- modernize
- makezero
- errorlint
settings:
errorlint:
# Switching %v to %w changes which errors callers can match with
# errors.Is/As (e.g. fs.ErrNotExist, context.Canceled), so it needs
# per-site review rather than a bulk fix.
errorf: false
modernize:
# omitzero changes JSON wire format for nested structs (unlike omitempty),
# so each site needs per-site review rather than a bulk rewrite.
Expand Down
4 changes: 2 additions & 2 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ func formatOutput(w io.Writer, err error) {
if err == nil {
return
}
if exiterr, ok := err.(*exec.ExitError); ok {
if exiterr, ok := errors.AsType[*exec.ExitError](err); ok {
exitCode := exiterr.ExitCode()
fmt.Fprintf(w, "\nExit code: %d\n", exitCode)
} else {
Expand Down Expand Up @@ -1859,7 +1859,7 @@ func runWithLog(t *testing.T, cmd *exec.Cmd, out *os.File, tail bool, timeout ti
require.NoError(t, err)
}
}
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion acceptance/internal/prepare_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package internal
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"mime"
Expand Down Expand Up @@ -376,7 +377,7 @@ func normalizeMultipartBody(req *testserver.Request) (any, bool) {
parts := map[string]any{}
for {
part, err := mr.NextPart()
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion bundle/artifacts/tarball_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/tar"
"bytes"
"compress/gzip"
"errors"
"io"
"os"
"os/exec"
Expand All @@ -26,7 +27,7 @@ func tarEntries(t *testing.T, b []byte) map[string]string {
out := map[string]string{}
for {
hdr, err := tr.Next()
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion bundle/config/mutator/python/python_mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (m *pythonMutator) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagno
b.Metrics.PythonUpdatedResourcesCount += int64(result.UpdatedResources.Size())
b.Metrics.PythonAddedResourcesCount += int64(result.AddedResources.Size())

if err == mutateDiagsHasError {
if errors.Is(err, mutateDiagsHasError) {
if !mutateDiags.HasError() {
panic("mutateDiags has no error, but error is expected")
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/air/logstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ func TestClassifyLogError(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := classifyLogError(tt.err)
switch tt.want {
case errBricklensFeatureDisabled:
switch {
case errors.Is(tt.want, errBricklensFeatureDisabled):
assert.ErrorIs(t, got, errBricklensFeatureDisabled)
case nil:
case tt.want == nil:
assert.NoError(t, got)
default:
assert.ErrorIs(t, got, tt.want)
Expand Down
2 changes: 1 addition & 1 deletion cmd/auth/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func loadFromDatabricksCfg(ctx context.Context, cfg *config.Config) error {
return err
}
profile, err := resolveSection(cfg, iniFile)
if err == ErrNoMatchingProfiles {
if errors.Is(err, ErrNoMatchingProfiles) {
// it's also fine for Azure CLI or Databricks CLI, which
// are resolved by unified auth handling in the Go SDK.
return nil
Expand Down
3 changes: 2 additions & 1 deletion cmd/bundle/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bundle

import (
"encoding/json"
"errors"
"fmt"

"github.com/databricks/cli/bundle"
Expand Down Expand Up @@ -67,7 +68,7 @@ Please run this command before deploying to ensure configuration quality.`,
})
ctx := cmd.Context()

if err != nil && err != root.ErrAlreadyPrinted {
if err != nil && !errors.Is(err, root.ErrAlreadyPrinted) {
logdiag.LogError(ctx, err)
err = root.ErrAlreadyPrinted
}
Expand Down
2 changes: 1 addition & 1 deletion experimental/ssh/internal/client/agentshim.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func probeModelServices(ctx context.Context, apiClient *client.DatabricksClient)
it := catalog.NewAiGateway(apiClient).ListModelServices(ctx, catalog.ListModelServicesRequest{PageSize: modelServiceProbePageSize})
_, err := it.Next(ctx)
if err != nil {
if err == listing.ErrNoMoreItems {
if errors.Is(err, listing.ErrNoMoreItems) {
// endpoint is reachable but there are no results
return gatewayProbe{reachable: true}
}
Expand Down
3 changes: 2 additions & 1 deletion libs/appproxy/appproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package appproxy

import (
"context"
"errors"
"io"
"net"
"net/http"
Expand Down Expand Up @@ -113,7 +114,7 @@ func (p *Proxy) handleWebSocket(w http.ResponseWriter, r *http.Request) {
err = <-errc
if err != nil {
// If the error is not EOF, then there was a problem
if err != io.EOF {
if !errors.Is(err, io.EOF) {
// Log the error and perform cleanup
log.Warnf(r.Context(), "error copying messages: %v", err)
middlewareConn.Close()
Expand Down
4 changes: 2 additions & 2 deletions libs/databrickscfg/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (l profileFromHostLoader) Configure(cfg *config.Config) error {
// Check if this section matches the normalized host
return normalizeHost(key.Value()) == host
})
if err == errNoMatchingProfiles {
if errors.Is(err, errNoMatchingProfiles) {
return nil
}

Expand All @@ -197,7 +197,7 @@ func (l profileFromHostLoader) Configure(cfg *config.Config) error {
if names, ok := AsMultipleProfiles(err); ok && cfg.WorkspaceID != "" {
originalErr := err
match, err = l.disambiguateByWorkspaceID(ctx, configFile, host, cfg.WorkspaceID, names)
if err == errNoMatchingProfiles {
if errors.Is(err, errNoMatchingProfiles) {
// workspace_id didn't match any of the host-matching profiles.
// Fall back to the original ambiguity error.
log.Debugf(ctx, "workspace_id=%s did not match any profiles for host %s: %v", cfg.WorkspaceID, host, names)
Expand Down
2 changes: 1 addition & 1 deletion libs/databrickscfg/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func matchOrCreateSection(ctx context.Context, configFile *config.File, cfg *con
// Check if this section matches the normalized host
return normalizeHost(host) == normalizeHost(cfg.Host)
})
if err == errNoMatchingProfiles {
if errors.Is(err, errNoMatchingProfiles) {
section, err = configFile.NewSection(cfg.Profile)
if err != nil {
return nil, fmt.Errorf("cannot create new profile: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion libs/dyn/jsonloader/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func LoadJSON(data []byte, source string) (dyn.Value, error) {
// Start decoding from the top-level value
value, err := decodeValue(decoder, &offset)
if err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
err = errors.New("unexpected end of JSON input")
}
// Get the current offset for error reporting
Expand Down
6 changes: 3 additions & 3 deletions libs/dyn/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Walk(v Value, fn func(p Path, v Value) (Value, error)) (Value, error) {
func walk(v Value, p Path, fn func(p Path, v Value) (Value, error)) (Value, error) {
v, err := fn(p, v)
if err != nil {
if err == ErrSkip {
if errors.Is(err, ErrSkip) {
return v, nil
}
return InvalidValue, err
Expand All @@ -39,7 +39,7 @@ func walk(v Value, p Path, fn func(p Path, v Value) (Value, error)) (Value, erro
pk := pair.Key
pv := pair.Value
nv, err := walk(pv, append(p, Key(pk.MustString())), fn)
if err == ErrDrop {
if errors.Is(err, ErrDrop) {
continue
}
if err != nil {
Expand All @@ -53,7 +53,7 @@ func walk(v Value, p Path, fn func(p Path, v Value) (Value, error)) (Value, erro
out := make([]Value, 0, len(s))
for i := range s {
nv, err := walk(s[i], append(p, Index(i)), fn)
if err == ErrDrop {
if errors.Is(err, ErrDrop) {
continue
}
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion libs/dyn/walk_read_only.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dyn

import "errors"

// WalkReadOnly walks the configuration tree in readonly mode and calls the given function on each node.
// The callback may return ErrSkip to skip traversal of a subtree.
// If the callback returns another error, the walk is aborted, and the error is returned.
Expand All @@ -12,7 +14,7 @@ func WalkReadOnly(v Value, fn func(p Path, v Value) error) error {
// such that it can be passed to the callback function.
func walkReadOnly(v Value, p Path, fn func(p Path, v Value) error) error {
if err := fn(p, v); err != nil {
if err == ErrSkip {
if errors.Is(err, ErrSkip) {
return nil
}
return err
Expand Down
3 changes: 2 additions & 1 deletion libs/dyn/yamlloader/yaml.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package yamlloader

import (
"errors"
"io"

"github.com/databricks/cli/libs/dyn"
Expand All @@ -12,7 +13,7 @@ func LoadYAML(path string, r io.Reader) (dyn.Value, error) {
dec := yaml.NewDecoder(r)
err := dec.Decode(&node)
if err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
return dyn.NilValue, nil
}
return dyn.InvalidValue, err
Expand Down
3 changes: 2 additions & 1 deletion libs/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exec
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -190,7 +191,7 @@ func (e *Executor) ExecAndCapture(ctx context.Context, command string) (*ExecOut
err = cmd.Wait()
exitCode := 0
if err != nil {
if exitErr, ok := err.(*osexec.ExitError); ok {
if exitErr, ok := errors.AsType[*osexec.ExitError](err); ok {
exitCode = exitErr.ExitCode()
} else {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion libs/filer/files_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestMapUploadError(t *testing.T) {

// Other errors pass through unchanged.
other := errors.New("boom")
if got := mapUploadError(other, p); got != other {
if got := mapUploadError(other, p); got != other { //nolint:errorlint // must be the same error, not a wrapper
t.Errorf("mapUploadError(other) = %v, want it unchanged", got)
}
}
6 changes: 3 additions & 3 deletions libs/genie/agentstream/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func RenderDebug(r io.Reader, w io.Writer) error {
reader := NewSSEReader(r)
for {
ev, err := reader.Next()
if err == io.EOF {
if errors.Is(err, io.EOF) {
return nil
}
if err != nil {
Expand Down Expand Up @@ -92,7 +92,7 @@ func RenderText(ctx context.Context, r io.Reader, stdout, stderr io.Writer, adap

for {
ev, err := reader.Next()
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
if err != nil {
Expand Down Expand Up @@ -198,7 +198,7 @@ func RenderJSON(r io.Reader, stdout, stderr io.Writer, adapt AdapterFunc) (strin
loop:
for {
ev, err := reader.Next()
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion libs/git/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (ref *Reference) ResolvePath() (string, error) {
// `ref: refs/heads/my-branch` returns `my-branch`
func (ref *Reference) CurrentBranch() (string, error) {
branchRefPath, err := ref.ResolvePath()
if err == ErrNotAReferencePointer {
if errors.Is(err, ErrNotAReferencePointer) {
return "", ErrNotABranch
}
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion libs/tarpack/tarpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tarpack
import (
"archive/tar"
"bytes"
"errors"
"io"
"os"
"path/filepath"
Expand All @@ -26,7 +27,7 @@ func readTar(t *testing.T, b []byte) map[string]readEntry {
out := map[string]readEntry{}
for {
hdr, err := tr.Next()
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
require.NoError(t, err)
Expand Down
5 changes: 3 additions & 2 deletions libs/testserver/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"mime"
Expand Down Expand Up @@ -141,7 +142,7 @@ func ParseImportForm(req Request) (ImportForm, error) {
mr := multipart.NewReader(bytes.NewReader(req.Body), params["boundary"])
for {
part, err := mr.NextPart()
if err == io.EOF {
if errors.Is(err, io.EOF) {
return form, nil
}
if err != nil {
Expand Down Expand Up @@ -907,7 +908,7 @@ func AddDefaultHandlers(server *Server) {
var bundleID, snapshotID string
for {
p, err := mr.NextPart()
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion tools/testrunner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bufio"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -45,7 +46,7 @@ func getExitCode(err error) (int, error) {
if err == nil {
return 0, nil
}
if exitError, ok := err.(*exec.ExitError); ok {
if exitError, ok := errors.AsType[*exec.ExitError](err); ok {
if status, ok := exitError.Sys().(syscall.WaitStatus); ok {
return status.ExitStatus(), nil
}
Expand Down
Loading