From 070dc6813f733eb8af27d980b8e50520374575d4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:10:25 +0100 Subject: [PATCH 1/5] Bump golang.org/x/term from 0.26.0 to 0.27.0 (#1983) Bumps [golang.org/x/term](https://github.com/golang/term) from 0.26.0 to 0.27.0.
Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=golang.org/x/term&package-manager=go_modules&previous-version=0.26.0&new-version=0.27.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 7141ed768..d24f97f42 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( golang.org/x/mod v0.22.0 golang.org/x/oauth2 v0.24.0 golang.org/x/sync v0.9.0 - golang.org/x/term v0.26.0 + golang.org/x/term v0.27.0 golang.org/x/text v0.20.0 gopkg.in/ini.v1 v1.67.0 // Apache 2.0 gopkg.in/yaml.v3 v3.0.1 @@ -64,7 +64,7 @@ require ( go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/crypto v0.24.0 // indirect golang.org/x/net v0.26.0 // indirect - golang.org/x/sys v0.27.0 // indirect + golang.org/x/sys v0.28.0 // indirect golang.org/x/time v0.5.0 // indirect google.golang.org/api v0.182.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e // indirect diff --git a/go.sum b/go.sum index 5d2c53a37..a62dbdc6c 100644 --- a/go.sum +++ b/go.sum @@ -212,10 +212,10 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= -golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU= -golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= +golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= From ad1359c1eba6c74eb00bce714661d0c529e04594 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:14:20 +0100 Subject: [PATCH 2/5] Bump golang.org/x/sync from 0.9.0 to 0.10.0 (#1984) Bumps [golang.org/x/sync](https://github.com/golang/sync) from 0.9.0 to 0.10.0.
Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=golang.org/x/sync&package-manager=go_modules&previous-version=0.9.0&new-version=0.10.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d24f97f42..20a0e2895 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 golang.org/x/mod v0.22.0 golang.org/x/oauth2 v0.24.0 - golang.org/x/sync v0.9.0 + golang.org/x/sync v0.10.0 golang.org/x/term v0.27.0 golang.org/x/text v0.20.0 gopkg.in/ini.v1 v1.67.0 // Apache 2.0 diff --git a/go.sum b/go.sum index a62dbdc6c..bf70ca509 100644 --- a/go.sum +++ b/go.sum @@ -200,8 +200,8 @@ golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbht golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= -golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= From 67f08ba924394157aa70519e3389d28667e2589d Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Wed, 11 Dec 2024 09:40:14 +0100 Subject: [PATCH 3/5] Avoid panic if Config.Workspace.CurrentUser.User is not set (#1993) ## Changes Extra check to avoid panic if /api/2.0/preview/scim/v2/Me returns `{}` ## Tests Existing tests. --- bundle/config/mutator/expand_workspace_root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/config/mutator/expand_workspace_root.go b/bundle/config/mutator/expand_workspace_root.go index 3f0547de1..a29d129b0 100644 --- a/bundle/config/mutator/expand_workspace_root.go +++ b/bundle/config/mutator/expand_workspace_root.go @@ -28,7 +28,7 @@ func (m *expandWorkspaceRoot) Apply(ctx context.Context, b *bundle.Bundle) diag. } currentUser := b.Config.Workspace.CurrentUser - if currentUser == nil || currentUser.UserName == "" { + if currentUser == nil || currentUser.User == nil || currentUser.UserName == "" { return diag.Errorf("unable to expand workspace root: current user not set") } From 4236e7122f8d2fe66f5a95e5da49af8b8bdf2038 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Wed, 11 Dec 2024 09:44:22 +0100 Subject: [PATCH 4/5] Switch to `folders.FindDirWithLeaf` (#1963) ## Changes Remove two duplicate implementations of the same logic, switch everywhere to folders.FindDirWithLeaf. Add Abs() call to FindDirWithLeaf, it cannot really work on relative paths. ## Tests Existing tests. --- bundle/config/mutator/load_git_details.go | 6 +++- internal/bundle/helpers.go | 7 ++--- internal/git_fetch_test.go | 4 +-- libs/folders/folders.go | 4 +++ libs/git/info.go | 32 ++----------------- libs/vfs/leaf.go | 29 ----------------- libs/vfs/leaf_test.go | 38 ----------------------- 7 files changed, 16 insertions(+), 104 deletions(-) delete mode 100644 libs/vfs/leaf.go delete mode 100644 libs/vfs/leaf_test.go diff --git a/bundle/config/mutator/load_git_details.go b/bundle/config/mutator/load_git_details.go index 82255552a..5c263ac03 100644 --- a/bundle/config/mutator/load_git_details.go +++ b/bundle/config/mutator/load_git_details.go @@ -2,6 +2,8 @@ package mutator import ( "context" + "errors" + "os" "path/filepath" "github.com/databricks/cli/bundle" @@ -24,7 +26,9 @@ func (m *loadGitDetails) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagn var diags diag.Diagnostics info, err := git.FetchRepositoryInfo(ctx, b.BundleRoot.Native(), b.WorkspaceClient()) if err != nil { - diags = append(diags, diag.WarningFromErr(err)...) + if !errors.Is(err, os.ErrNotExist) { + diags = append(diags, diag.WarningFromErr(err)...) + } } if info.WorktreeRoot == "" { diff --git a/internal/bundle/helpers.go b/internal/bundle/helpers.go index dd9c841c9..00a941c95 100644 --- a/internal/bundle/helpers.go +++ b/internal/bundle/helpers.go @@ -18,8 +18,8 @@ import ( "github.com/databricks/cli/libs/env" "github.com/databricks/cli/libs/filer" "github.com/databricks/cli/libs/flags" + "github.com/databricks/cli/libs/folders" "github.com/databricks/cli/libs/template" - "github.com/databricks/cli/libs/vfs" "github.com/databricks/databricks-sdk-go" "github.com/stretchr/testify/require" ) @@ -144,15 +144,14 @@ func getBundleRemoteRootPath(w *databricks.WorkspaceClient, t *testing.T, unique } func blackBoxRun(t *testing.T, root string, args ...string) (stdout string, stderr string) { - cwd := vfs.MustNew(".") - gitRoot, err := vfs.FindLeafInTree(cwd, ".git") + gitRoot, err := folders.FindDirWithLeaf(".", ".git") require.NoError(t, err) t.Setenv("BUNDLE_ROOT", root) // Create the command cmd := exec.Command("go", append([]string{"run", "main.go"}, args...)...) - cmd.Dir = gitRoot.Native() + cmd.Dir = gitRoot // Create buffers to capture output var outBuffer, errBuffer bytes.Buffer diff --git a/internal/git_fetch_test.go b/internal/git_fetch_test.go index 5dab6be76..3da024a3a 100644 --- a/internal/git_fetch_test.go +++ b/internal/git_fetch_test.go @@ -101,7 +101,7 @@ func TestAccFetchRepositoryInfoAPI_FromNonRepo(t *testing.T) { assert.NoError(t, err) } else { assert.Error(t, err) - assert.Contains(t, err.Error(), test.msg) + assert.ErrorContains(t, err, test.msg) } assertEmptyGitInfo(t, info) }) @@ -151,7 +151,7 @@ func TestAccFetchRepositoryInfoDotGit_FromNonGitRepo(t *testing.T) { for _, input := range tests { t.Run(input, func(t *testing.T) { info, err := git.FetchRepositoryInfo(ctx, input, wt.W) - assert.NoError(t, err) + assert.ErrorIs(t, err, os.ErrNotExist) assertEmptyGitInfo(t, info) }) } diff --git a/libs/folders/folders.go b/libs/folders/folders.go index c83c711d3..81bf7ed01 100644 --- a/libs/folders/folders.go +++ b/libs/folders/folders.go @@ -9,6 +9,10 @@ import ( // FindDirWithLeaf returns the first directory that holds `leaf`, // traversing up to the root of the filesystem, starting at `dir`. func FindDirWithLeaf(dir string, leaf string) (string, error) { + dir, err := filepath.Abs(dir) + if err != nil { + return "", err + } for { _, err := os.Stat(filepath.Join(dir, leaf)) diff --git a/libs/git/info.go b/libs/git/info.go index 13c298113..ce9c70a5c 100644 --- a/libs/git/info.go +++ b/libs/git/info.go @@ -2,15 +2,12 @@ package git import ( "context" - "errors" - "io/fs" "net/http" - "os" "path" - "path/filepath" "strings" "github.com/databricks/cli/libs/dbr" + "github.com/databricks/cli/libs/folders" "github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/vfs" "github.com/databricks/databricks-sdk-go" @@ -105,7 +102,7 @@ func ensureWorkspacePrefix(p string) string { func fetchRepositoryInfoDotGit(ctx context.Context, path string) (RepositoryInfo, error) { result := RepositoryInfo{} - rootDir, err := findLeafInTree(path, GitDirectoryName) + rootDir, err := folders.FindDirWithLeaf(path, GitDirectoryName) if rootDir == "" { return result, err } @@ -134,28 +131,3 @@ func fetchRepositoryInfoDotGit(ctx context.Context, path string) (RepositoryInfo return result, nil } - -func findLeafInTree(p string, leafName string) (string, error) { - var err error - for i := 0; i < 10000; i++ { - _, err = os.Stat(filepath.Join(p, leafName)) - - if err == nil { - // Found [leafName] in p - return p, nil - } - - // ErrNotExist means we continue traversal up the tree. - if errors.Is(err, fs.ErrNotExist) { - parent := filepath.Dir(p) - if parent == p { - return "", nil - } - p = parent - continue - } - break - } - - return "", err -} diff --git a/libs/vfs/leaf.go b/libs/vfs/leaf.go deleted file mode 100644 index 8c11f9039..000000000 --- a/libs/vfs/leaf.go +++ /dev/null @@ -1,29 +0,0 @@ -package vfs - -import ( - "errors" - "io/fs" -) - -// FindLeafInTree returns the first path that holds `name`, -// traversing up to the root of the filesystem, starting at `p`. -func FindLeafInTree(p Path, name string) (Path, error) { - for p != nil { - _, err := fs.Stat(p, name) - - // No error means we found the leaf in p. - if err == nil { - return p, nil - } - - // ErrNotExist means we continue traversal up the tree. - if errors.Is(err, fs.ErrNotExist) { - p = p.Parent() - continue - } - - return nil, err - } - - return nil, fs.ErrNotExist -} diff --git a/libs/vfs/leaf_test.go b/libs/vfs/leaf_test.go deleted file mode 100644 index da9412ec0..000000000 --- a/libs/vfs/leaf_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package vfs - -import ( - "os" - "path/filepath" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestFindLeafInTree(t *testing.T) { - wd, err := os.Getwd() - require.NoError(t, err) - - root := filepath.Join(wd, "..", "..") - - // Find from working directory should work. - { - out, err := FindLeafInTree(MustNew(wd), ".git") - assert.NoError(t, err) - assert.Equal(t, root, out.Native()) - } - - // Find from project root itself should work. - { - out, err := FindLeafInTree(MustNew(root), ".git") - assert.NoError(t, err) - assert.Equal(t, root, out.Native()) - } - - // Find for something that doesn't exist should work. - { - out, err := FindLeafInTree(MustNew(root), "this-leaf-doesnt-exist-anywhere") - assert.ErrorIs(t, err, os.ErrNotExist) - assert.Equal(t, nil, out) - } -} From 8d5351c1c3d7befda4baae5d6adb99367aa50b3c Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Wed, 11 Dec 2024 13:26:00 +0100 Subject: [PATCH 5/5] Enable errcheck everywhere and fix or silent remaining issues (#1987) ## Changes Enable errcheck linter for the whole codebase. Fix remaining complaints: - If we can propagate error to caller, do that - If we writing to stdout, continue ignoring errors (to avoid crashing in "cli | head" case) - Add exception for cobra non-critical API such as MarkHidden/MarkDeprecated/RegisterFlagCompletionFunc. This keeps current code and behaviour, to be decided later if we want to change this. - Continue ignoring errors where that is desired behaviour (e.g. git.loadConfig). - Continue ignoring errors where panicking seems riskier than ignoring the error. - Annotate cases in libs/dyn with //nolint:errcheck - to be addressed later. Note, this PR is not meant to come up with the best strategy for each case, but to be a relative safe change to enable errcheck linter. ## Tests Existing tests. --- .golangci.yaml | 10 +++++---- bundle/config/mutator/initialize_urls.go | 5 ++++- .../mutator/resolve_resource_references.go | 3 +-- bundle/deploy/state_pull.go | 10 +++++++-- bundle/render/render_text_output.go | 10 +++++++-- cmd/auth/describe.go | 5 ++++- cmd/auth/env.go | 2 +- cmd/auth/token.go | 2 +- cmd/bundle/debug/terraform.go | 4 ++-- cmd/bundle/run.go | 10 +++++++-- cmd/bundle/summary.go | 2 +- cmd/bundle/validate.go | 2 +- cmd/root/io.go | 2 +- cmd/root/logger.go | 11 ++++++---- cmd/root/progress_logger.go | 2 +- libs/auth/callback.go | 4 +++- libs/cmdio/logger.go | 18 ++++++++-------- libs/cmdio/render.go | 4 +++- libs/dyn/convert/from_typed.go | 4 ++-- libs/dyn/convert/normalize.go | 6 +++--- libs/dyn/jsonloader/json.go | 2 +- libs/dyn/mapping.go | 4 ++-- libs/dyn/merge/merge.go | 4 ++-- libs/dyn/pattern.go | 2 +- libs/dyn/visit.go | 2 +- libs/dyn/visit_map.go | 2 +- libs/dyn/visit_set.go | 2 +- libs/dyn/walk.go | 2 +- libs/dyn/yamlloader/loader.go | 2 +- libs/env/loader.go | 4 +++- libs/git/config.go | 4 ++-- libs/process/stub.go | 21 ++++++++++++++----- libs/sync/output.go | 6 +++--- 33 files changed, 109 insertions(+), 64 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 602f12630..6ab8bb2fe 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -16,9 +16,11 @@ linters-settings: replacement: 'a[b:]' - pattern: 'interface{}' replacement: 'any' + errcheck: + exclude-functions: + - (*github.com/spf13/cobra.Command).RegisterFlagCompletionFunc + - (*github.com/spf13/cobra.Command).MarkFlagRequired + - (*github.com/spf13/pflag.FlagSet).MarkDeprecated + - (*github.com/spf13/pflag.FlagSet).MarkHidden issues: exclude-dirs-use-default: false # recommended by docs https://golangci-lint.run/usage/false-positives/ - exclude-rules: - - path-except: (_test\.go|internal) - linters: - - errcheck diff --git a/bundle/config/mutator/initialize_urls.go b/bundle/config/mutator/initialize_urls.go index 319305912..4cf7ed72c 100644 --- a/bundle/config/mutator/initialize_urls.go +++ b/bundle/config/mutator/initialize_urls.go @@ -32,7 +32,10 @@ func (m *initializeURLs) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagn } orgId := strconv.FormatInt(workspaceId, 10) host := b.WorkspaceClient().Config.CanonicalHostName() - initializeForWorkspace(b, orgId, host) + err = initializeForWorkspace(b, orgId, host) + if err != nil { + return diag.FromErr(err) + } return nil } diff --git a/bundle/config/mutator/resolve_resource_references.go b/bundle/config/mutator/resolve_resource_references.go index 89eaa346c..bf902f928 100644 --- a/bundle/config/mutator/resolve_resource_references.go +++ b/bundle/config/mutator/resolve_resource_references.go @@ -36,8 +36,7 @@ func (m *resolveResourceReferences) Apply(ctx context.Context, b *bundle.Bundle) return fmt.Errorf("failed to resolve %s, err: %w", v.Lookup, err) } - v.Set(id) - return nil + return v.Set(id) }) } diff --git a/bundle/deploy/state_pull.go b/bundle/deploy/state_pull.go index 5e301a6f3..96f138e9d 100644 --- a/bundle/deploy/state_pull.go +++ b/bundle/deploy/state_pull.go @@ -62,8 +62,14 @@ func (s *statePull) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostic } // Truncating the file before writing - local.Truncate(0) - local.Seek(0, 0) + err = local.Truncate(0) + if err != nil { + return diag.FromErr(err) + } + _, err = local.Seek(0, 0) + if err != nil { + return diag.FromErr(err) + } // Write file to disk. log.Infof(ctx, "Writing remote deployment state file to local cache directory") diff --git a/bundle/render/render_text_output.go b/bundle/render/render_text_output.go index 92dacb448..bf7c9a53a 100644 --- a/bundle/render/render_text_output.go +++ b/bundle/render/render_text_output.go @@ -171,10 +171,16 @@ func RenderDiagnostics(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics, if err != nil { return fmt.Errorf("failed to render summary: %w", err) } - io.WriteString(out, "\n") + _, err = io.WriteString(out, "\n") + if err != nil { + return err + } } trailer := buildTrailer(diags) - io.WriteString(out, trailer) + _, err = io.WriteString(out, trailer) + if err != nil { + return err + } } return nil diff --git a/cmd/auth/describe.go b/cmd/auth/describe.go index 3a6e3d5d7..c5fa8d26b 100644 --- a/cmd/auth/describe.go +++ b/cmd/auth/describe.go @@ -141,7 +141,10 @@ func render(ctx context.Context, cmd *cobra.Command, status *authStatus, templat if err != nil { return err } - cmd.OutOrStdout().Write(buf) + _, err = cmd.OutOrStdout().Write(buf) + if err != nil { + return err + } default: return fmt.Errorf("unknown output type %s", root.OutputType(cmd)) } diff --git a/cmd/auth/env.go b/cmd/auth/env.go index e72d15399..52b7cbbfd 100644 --- a/cmd/auth/env.go +++ b/cmd/auth/env.go @@ -138,7 +138,7 @@ func newEnvCommand() *cobra.Command { if err != nil { return err } - cmd.OutOrStdout().Write(raw) + _, _ = cmd.OutOrStdout().Write(raw) return nil } diff --git a/cmd/auth/token.go b/cmd/auth/token.go index 3f9af43fa..fbf8b68f6 100644 --- a/cmd/auth/token.go +++ b/cmd/auth/token.go @@ -94,7 +94,7 @@ func newTokenCommand(persistentAuth *auth.PersistentAuth) *cobra.Command { if err != nil { return err } - cmd.OutOrStdout().Write(raw) + _, _ = cmd.OutOrStdout().Write(raw) return nil } diff --git a/cmd/bundle/debug/terraform.go b/cmd/bundle/debug/terraform.go index 843ecac4e..c7d49ebb2 100644 --- a/cmd/bundle/debug/terraform.go +++ b/cmd/bundle/debug/terraform.go @@ -60,13 +60,13 @@ For more information about filesystem mirrors, see the Terraform documentation: } switch root.OutputType(cmd) { case flags.OutputText: - cmdio.Render(cmd.Context(), dependencies.Terraform) + _ = cmdio.Render(cmd.Context(), dependencies.Terraform) case flags.OutputJSON: buf, err := json.MarshalIndent(dependencies, "", " ") if err != nil { return err } - cmd.OutOrStdout().Write(buf) + _, _ = cmd.OutOrStdout().Write(buf) default: return fmt.Errorf("unknown output type %s", root.OutputType(cmd)) } diff --git a/cmd/bundle/run.go b/cmd/bundle/run.go index 7a92766d9..3bcebddd5 100644 --- a/cmd/bundle/run.go +++ b/cmd/bundle/run.go @@ -159,13 +159,19 @@ task or a Python wheel task, the second example applies. if err != nil { return err } - cmd.OutOrStdout().Write([]byte(resultString)) + _, err = cmd.OutOrStdout().Write([]byte(resultString)) + if err != nil { + return err + } case flags.OutputJSON: b, err := json.MarshalIndent(output, "", " ") if err != nil { return err } - cmd.OutOrStdout().Write(b) + _, err = cmd.OutOrStdout().Write(b) + if err != nil { + return err + } default: return fmt.Errorf("unknown output type %s", root.OutputType(cmd)) } diff --git a/cmd/bundle/summary.go b/cmd/bundle/summary.go index 8c34dd612..7c669c845 100644 --- a/cmd/bundle/summary.go +++ b/cmd/bundle/summary.go @@ -73,7 +73,7 @@ func newSummaryCommand() *cobra.Command { if err != nil { return err } - cmd.OutOrStdout().Write(buf) + _, _ = cmd.OutOrStdout().Write(buf) default: return fmt.Errorf("unknown output type %s", root.OutputType(cmd)) } diff --git a/cmd/bundle/validate.go b/cmd/bundle/validate.go index 5331e7e7b..3b50cc258 100644 --- a/cmd/bundle/validate.go +++ b/cmd/bundle/validate.go @@ -20,7 +20,7 @@ func renderJsonOutput(cmd *cobra.Command, b *bundle.Bundle, diags diag.Diagnosti if err != nil { return err } - cmd.OutOrStdout().Write(buf) + _, _ = cmd.OutOrStdout().Write(buf) return diags.Error() } diff --git a/cmd/root/io.go b/cmd/root/io.go index b224bbb27..96c5a9a26 100644 --- a/cmd/root/io.go +++ b/cmd/root/io.go @@ -21,7 +21,7 @@ func initOutputFlag(cmd *cobra.Command) *outputFlag { // Configure defaults from environment, if applicable. // If the provided value is invalid it is ignored. if v, ok := env.Lookup(cmd.Context(), envOutputFormat); ok { - f.output.Set(v) + f.output.Set(v) //nolint:errcheck } cmd.PersistentFlags().VarP(&f.output, "output", "o", "output type: text or json") diff --git a/cmd/root/logger.go b/cmd/root/logger.go index 48cb99a37..38e09b9c9 100644 --- a/cmd/root/logger.go +++ b/cmd/root/logger.go @@ -45,7 +45,10 @@ func (f *logFlags) makeLogHandler(opts slog.HandlerOptions) (slog.Handler, error func (f *logFlags) initializeContext(ctx context.Context) (context.Context, error) { if f.debug { - f.level.Set("debug") + err := f.level.Set("debug") + if err != nil { + return nil, err + } } opts := slog.HandlerOptions{} @@ -81,13 +84,13 @@ func initLogFlags(cmd *cobra.Command) *logFlags { // Configure defaults from environment, if applicable. // If the provided value is invalid it is ignored. if v, ok := env.Lookup(cmd.Context(), envLogFile); ok { - f.file.Set(v) + f.file.Set(v) //nolint:errcheck } if v, ok := env.Lookup(cmd.Context(), envLogLevel); ok { - f.level.Set(v) + f.level.Set(v) //nolint:errcheck } if v, ok := env.Lookup(cmd.Context(), envLogFormat); ok { - f.output.Set(v) + f.output.Set(v) //nolint:errcheck } flags := cmd.PersistentFlags() diff --git a/cmd/root/progress_logger.go b/cmd/root/progress_logger.go index 7d6a1fa46..1458de13a 100644 --- a/cmd/root/progress_logger.go +++ b/cmd/root/progress_logger.go @@ -59,7 +59,7 @@ func initProgressLoggerFlag(cmd *cobra.Command, logFlags *logFlags) *progressLog // Configure defaults from environment, if applicable. // If the provided value is invalid it is ignored. if v, ok := env.Lookup(cmd.Context(), envProgressFormat); ok { - f.Set(v) + _ = f.Set(v) } flags := cmd.PersistentFlags() diff --git a/libs/auth/callback.go b/libs/auth/callback.go index 5a2400697..3893a5041 100644 --- a/libs/auth/callback.go +++ b/libs/auth/callback.go @@ -53,7 +53,9 @@ func newCallback(ctx context.Context, a *PersistentAuth) (*callbackServer, error a: a, } cb.srv.Handler = cb - go cb.srv.Serve(cb.ln) + go func() { + _ = cb.srv.Serve(cb.ln) + }() return cb, nil } diff --git a/libs/cmdio/logger.go b/libs/cmdio/logger.go index 45b1883ce..5e89b3a34 100644 --- a/libs/cmdio/logger.go +++ b/libs/cmdio/logger.go @@ -188,29 +188,29 @@ func (l *Logger) writeJson(event Event) { // we panic because there we cannot catch this in jobs.RunNowAndWait panic(err) } - l.Writer.Write([]byte(b)) - l.Writer.Write([]byte("\n")) + _, _ = l.Writer.Write([]byte(b)) + _, _ = l.Writer.Write([]byte("\n")) } func (l *Logger) writeAppend(event Event) { - l.Writer.Write([]byte(event.String())) - l.Writer.Write([]byte("\n")) + _, _ = l.Writer.Write([]byte(event.String())) + _, _ = l.Writer.Write([]byte("\n")) } func (l *Logger) writeInplace(event Event) { if l.isFirstEvent { // save cursor location - l.Writer.Write([]byte("\033[s")) + _, _ = l.Writer.Write([]byte("\033[s")) } // move cursor to saved location - l.Writer.Write([]byte("\033[u")) + _, _ = l.Writer.Write([]byte("\033[u")) // clear from cursor to end of screen - l.Writer.Write([]byte("\033[0J")) + _, _ = l.Writer.Write([]byte("\033[0J")) - l.Writer.Write([]byte(event.String())) - l.Writer.Write([]byte("\n")) + _, _ = l.Writer.Write([]byte(event.String())) + _, _ = l.Writer.Write([]byte("\n")) l.isFirstEvent = false } diff --git a/libs/cmdio/render.go b/libs/cmdio/render.go index c68ddca0d..1529274a3 100644 --- a/libs/cmdio/render.go +++ b/libs/cmdio/render.go @@ -361,7 +361,9 @@ func renderUsingTemplate(ctx context.Context, r templateRenderer, w io.Writer, h if err != nil { return err } - tw.Write([]byte("\n")) + if _, err := tw.Write([]byte("\n")); err != nil { + return err + } // Do not flush here. Instead, allow the first 100 resources to determine the initial spacing of the header columns. } t, err := base.Parse(tmpl) diff --git a/libs/dyn/convert/from_typed.go b/libs/dyn/convert/from_typed.go index cd92ad0eb..ed1b85a36 100644 --- a/libs/dyn/convert/from_typed.go +++ b/libs/dyn/convert/from_typed.go @@ -126,7 +126,7 @@ func fromTypedStruct(src reflect.Value, ref dyn.Value, options ...fromTypedOptio // Either if the key was set in the reference or the field is not zero-valued, we include it. if ok || nv.Kind() != dyn.KindNil { - out.Set(refk, nv) + out.Set(refk, nv) // nolint:errcheck } } @@ -184,7 +184,7 @@ func fromTypedMap(src reflect.Value, ref dyn.Value) (dyn.Value, error) { // Every entry is represented, even if it is a nil. // Otherwise, a map with zero-valued structs would yield a nil as well. - out.Set(refk, nv) + out.Set(refk, nv) //nolint:errcheck } return dyn.V(out), nil diff --git a/libs/dyn/convert/normalize.go b/libs/dyn/convert/normalize.go index 106add35d..31cd8b6e3 100644 --- a/libs/dyn/convert/normalize.go +++ b/libs/dyn/convert/normalize.go @@ -116,7 +116,7 @@ func (n normalizeOptions) normalizeStruct(typ reflect.Type, src dyn.Value, seen } } - out.Set(pk, nv) + out.Set(pk, nv) //nolint:errcheck } // Return the normalized value if missing fields are not included. @@ -162,7 +162,7 @@ func (n normalizeOptions) normalizeStruct(typ reflect.Type, src dyn.Value, seen continue } if v.IsValid() { - out.Set(dyn.V(k), v) + out.Set(dyn.V(k), v) // nolint:errcheck } } @@ -201,7 +201,7 @@ func (n normalizeOptions) normalizeMap(typ reflect.Type, src dyn.Value, seen []r } } - out.Set(pk, nv) + out.Set(pk, nv) //nolint:errcheck } return dyn.NewValue(out, src.Locations()), diags diff --git a/libs/dyn/jsonloader/json.go b/libs/dyn/jsonloader/json.go index cbf539263..3f2dc859f 100644 --- a/libs/dyn/jsonloader/json.go +++ b/libs/dyn/jsonloader/json.go @@ -70,7 +70,7 @@ func decodeValue(decoder *json.Decoder, o *Offset) (dyn.Value, error) { return invalidValueWithLocation(decoder, o), err } - obj.Set(keyVal, val) + obj.Set(keyVal, val) //nolint:errcheck } // Consume the closing '}' if _, err := decoder.Token(); err != nil { diff --git a/libs/dyn/mapping.go b/libs/dyn/mapping.go index f9f2d2e97..f5dbd18e6 100644 --- a/libs/dyn/mapping.go +++ b/libs/dyn/mapping.go @@ -41,7 +41,7 @@ func newMappingWithSize(size int) Mapping { func newMappingFromGoMap(vin map[string]Value) Mapping { m := newMappingWithSize(len(vin)) for k, v := range vin { - m.Set(V(k), v) + m.Set(V(k), v) //nolint:errcheck } return m } @@ -144,6 +144,6 @@ func (m Mapping) Clone() Mapping { // Merge merges the key-value pairs from another Mapping into the current Mapping. func (m *Mapping) Merge(n Mapping) { for _, p := range n.pairs { - m.Set(p.Key, p.Value) + m.Set(p.Key, p.Value) //nolint:errcheck } } diff --git a/libs/dyn/merge/merge.go b/libs/dyn/merge/merge.go index 29decd779..a83bbc152 100644 --- a/libs/dyn/merge/merge.go +++ b/libs/dyn/merge/merge.go @@ -88,10 +88,10 @@ func mergeMap(a, b dyn.Value) (dyn.Value, error) { if err != nil { return dyn.InvalidValue, err } - out.Set(pk, merged) + out.Set(pk, merged) //nolint:errcheck } else { // Otherwise, just set the value. - out.Set(pk, pv) + out.Set(pk, pv) //nolint:errcheck } } diff --git a/libs/dyn/pattern.go b/libs/dyn/pattern.go index aecdc3ca6..2d2e9cae7 100644 --- a/libs/dyn/pattern.go +++ b/libs/dyn/pattern.go @@ -69,7 +69,7 @@ func (c anyKeyComponent) visit(v Value, prefix Path, suffix Pattern, opts visitO return InvalidValue, err } - m.Set(pk, nv) + m.Set(pk, nv) //nolint:errcheck } return NewValue(m, v.Locations()), nil diff --git a/libs/dyn/visit.go b/libs/dyn/visit.go index 38adec24f..95515115e 100644 --- a/libs/dyn/visit.go +++ b/libs/dyn/visit.go @@ -122,7 +122,7 @@ func (component pathComponent) visit(v Value, prefix Path, suffix Pattern, opts // Return an updated map value. m = m.Clone() - m.Set(V(component.key), nv) + m.Set(V(component.key), nv) //nolint:errcheck return Value{ v: m, k: KindMap, diff --git a/libs/dyn/visit_map.go b/libs/dyn/visit_map.go index 3f0cded03..db4526038 100644 --- a/libs/dyn/visit_map.go +++ b/libs/dyn/visit_map.go @@ -25,7 +25,7 @@ func Foreach(fn MapFunc) MapFunc { if err != nil { return InvalidValue, err } - m.Set(pk, nv) + m.Set(pk, nv) //nolint:errcheck } return NewValue(m, v.Locations()), nil case KindSequence: diff --git a/libs/dyn/visit_set.go b/libs/dyn/visit_set.go index b086fb8a9..9991d311f 100644 --- a/libs/dyn/visit_set.go +++ b/libs/dyn/visit_set.go @@ -41,7 +41,7 @@ func SetByPath(v Value, p Path, nv Value) (Value, error) { // Return an updated map value. m = m.Clone() - m.Set(V(component.key), nv) + m.Set(V(component.key), nv) //nolint:errcheck return Value{ v: m, k: KindMap, diff --git a/libs/dyn/walk.go b/libs/dyn/walk.go index c51a11e22..b3576e088 100644 --- a/libs/dyn/walk.go +++ b/libs/dyn/walk.go @@ -45,7 +45,7 @@ func walk(v Value, p Path, fn func(p Path, v Value) (Value, error)) (Value, erro if err != nil { return InvalidValue, err } - out.Set(pk, nv) + out.Set(pk, nv) //nolint:errcheck } v.v = out case KindSequence: diff --git a/libs/dyn/yamlloader/loader.go b/libs/dyn/yamlloader/loader.go index a77ee0744..965753ccd 100644 --- a/libs/dyn/yamlloader/loader.go +++ b/libs/dyn/yamlloader/loader.go @@ -129,7 +129,7 @@ func (d *loader) loadMapping(node *yaml.Node, loc dyn.Location) (dyn.Value, erro return dyn.InvalidValue, err } - acc.Set(k, v) + acc.Set(k, v) //nolint:errcheck } if merge == nil { diff --git a/libs/env/loader.go b/libs/env/loader.go index f441ffa15..74c54cee8 100644 --- a/libs/env/loader.go +++ b/libs/env/loader.go @@ -43,7 +43,9 @@ func (le *configLoader) Configure(cfg *config.Config) error { if v == "" { continue } - a.Set(cfg, v) + if err := a.Set(cfg, v); err != nil { + return err + } } } return nil diff --git a/libs/git/config.go b/libs/git/config.go index fafd81bd6..f7ff057e1 100644 --- a/libs/git/config.go +++ b/libs/git/config.go @@ -155,8 +155,8 @@ func globalGitConfig() (*config, error) { // > are missing or unreadable they will be ignored. // // We therefore ignore the error return value for the calls below. - config.loadFile(vfs.MustNew(xdgConfigHome), "git/config") - config.loadFile(vfs.MustNew(config.home), ".gitconfig") + _ = config.loadFile(vfs.MustNew(xdgConfigHome), "git/config") + _ = config.loadFile(vfs.MustNew(config.home), ".gitconfig") return config, nil } diff --git a/libs/process/stub.go b/libs/process/stub.go index 8472f65d5..8ab6fd705 100644 --- a/libs/process/stub.go +++ b/libs/process/stub.go @@ -148,13 +148,20 @@ func (s *processStub) run(cmd *exec.Cmd) error { if !re.MatchString(norm) { continue } + err := resp.err if resp.stdout != "" { - cmd.Stdout.Write([]byte(resp.stdout)) + _, err1 := cmd.Stdout.Write([]byte(resp.stdout)) + if err == nil { + err = err1 + } } if resp.stderr != "" { - cmd.Stderr.Write([]byte(resp.stderr)) + _, err1 := cmd.Stderr.Write([]byte(resp.stderr)) + if err == nil { + err = err1 + } } - return resp.err + return err } if s.callback != nil { return s.callback(cmd) @@ -163,8 +170,12 @@ func (s *processStub) run(cmd *exec.Cmd) error { if s.reponseStub == zeroStub { return fmt.Errorf("no default process stub") } + err := s.reponseStub.err if s.reponseStub.stdout != "" { - cmd.Stdout.Write([]byte(s.reponseStub.stdout)) + _, err1 := cmd.Stdout.Write([]byte(s.reponseStub.stdout)) + if err == nil { + err = err1 + } } - return s.reponseStub.err + return err } diff --git a/libs/sync/output.go b/libs/sync/output.go index c01b25ef6..e6ac8c56c 100644 --- a/libs/sync/output.go +++ b/libs/sync/output.go @@ -43,9 +43,9 @@ func TextOutput(ctx context.Context, ch <-chan Event, w io.Writer) { // Log only if something actually happened. // Sync events produce an empty string if nothing happened. if str := e.String(); str != "" { - bw.WriteString(str) - bw.WriteString("\n") - bw.Flush() + _, _ = bw.WriteString(str) + _, _ = bw.WriteString("\n") + _ = bw.Flush() } } }