Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove dependency on multierror #5275

Merged
merged 5 commits into from
Feb 2, 2025
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ require (
github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.3
github.com/hashicorp/go-getter/v2 v2.2.3
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-version v1.7.0
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/hashicorp/hc-install v0.9.0
Expand Down Expand Up @@ -96,6 +95,7 @@ require (
github.com/gorilla/css v1.0.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ Ran Approve Policies for 1 projects:
### 1. dir: `.` workspace: `default`
**Approve Policies Error**
```
1 error occurred:
* policy set: test_policy user runatlantis is not a policy owner - please contact policy owners to approve failing policies


policy set: test_policy user runatlantis is not a policy owner - please contact policy owners to approve failing policies
```
#### Policy Approval Status:
```
Expand Down
21 changes: 8 additions & 13 deletions server/core/runtime/policy/conftest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package policy

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
Expand All @@ -12,9 +13,9 @@ import (
"regexp"

"github.com/hashicorp/go-getter/v2"
"github.com/hashicorp/go-multierror"

version "github.com/hashicorp/go-version"
"github.com/pkg/errors"

"github.com/runatlantis/atlantis/server/core/config/valid"
"github.com/runatlantis/atlantis/server/core/runtime/cache"
runtime_models "github.com/runatlantis/atlantis/server/core/runtime/models"
Expand Down Expand Up @@ -139,7 +140,7 @@ func (c ConfTestVersionDownloader) downloadConfTestVersion(v *version.Version, d
fullSrcURL := fmt.Sprintf("%s?checksum=file:%s", binURL, checksumURL)

if err := c.downloader.GetAny(destPath, fullSrcURL); err != nil {
return runtime_models.LocalFilePath(""), errors.Wrapf(err, "downloading conftest version %s at %q", v.String(), fullSrcURL)
return runtime_models.LocalFilePath(""), fmt.Errorf("downloading conftest version %s at %q: %w", v.String(), fullSrcURL, err)
}

binPath := filepath.Join(destPath, "conftest")
Expand Down Expand Up @@ -212,9 +213,9 @@ func (c *ConfTestExecutorWorkflow) Run(ctx command.ProjectContext, executablePat
if cmdErr != nil {
// Since we're running conftest for each policyset, individual command errors should be concatenated.
if isValidConftestOutput(cmdOutput) {
combinedErr = multierror.Append(combinedErr, fmt.Errorf("policy_set: %s: conftest: some policies failed", policySet.Name))
combinedErr = errors.Join(combinedErr, fmt.Errorf("policy_set: %s: conftest: some policies failed", policySet.Name))
} else {
combinedErr = multierror.Append(combinedErr, fmt.Errorf("policy_set: %s: conftest: %s", policySet.Name, cmdOutput))
combinedErr = errors.Join(combinedErr, fmt.Errorf("policy_set: %s: conftest: %s", policySet.Name, cmdOutput))
}
}

Expand Down Expand Up @@ -247,13 +248,7 @@ func (c *ConfTestExecutorWorkflow) Run(ctx command.ProjectContext, executablePat
policyCheckResultFile := filepath.Join(workdir, ctx.GetPolicyCheckResultFileName())
err = os.WriteFile(policyCheckResultFile, marshaledStatus, 0600)

combinedErr = multierror.Append(combinedErr, err)

// Multierror will wrap combined errors in a way that the upstream functions won't be able to read it as nil.
// Let's pass nil back if there are no wrapped errors.
if errors.Unwrap(combinedErr) == nil {
combinedErr = nil
}
combinedErr = errors.Join(combinedErr, err)

output := string(marshaledStatus)

Expand Down Expand Up @@ -306,7 +301,7 @@ func getDefaultVersion() (*version.Version, error) {
wrappedVersion, err := version.NewVersion(defaultVersion)

if err != nil {
return nil, errors.Wrapf(err, "wrapping version %s", defaultVersion)
return nil, fmt.Errorf("wrapping version %s: %w", defaultVersion, err)
}
return wrappedVersion, nil
}
Expand Down
21 changes: 10 additions & 11 deletions server/events/project_command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ package events

import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"github.com/runatlantis/atlantis/server/core/config/valid"
"github.com/runatlantis/atlantis/server/core/runtime"
"github.com/runatlantis/atlantis/server/events/command"
Expand Down Expand Up @@ -347,7 +346,7 @@ func (p *DefaultProjectCommandRunner) doApprovePolicies(ctx command.ProjectConte
// Acquire Atlantis lock for this repo/dir/workspace.
lockAttempt, err := p.Locker.TryLock(ctx.Log, ctx.Pull, ctx.User, ctx.Workspace, models.NewProject(ctx.Pull.BaseRepo.FullName, ctx.RepoRelDir, ctx.ProjectName), ctx.RepoLocksMode == valid.RepoLocksOnPlanMode)
if err != nil {
return nil, "", errors.Wrap(err, "acquiring lock")
return nil, "", fmt.Errorf("acquiring lock: %w", err)
}
if !lockAttempt.LockAcquired {
return nil, lockAttempt.LockFailureReason, nil
Expand Down Expand Up @@ -408,10 +407,10 @@ func (p *DefaultProjectCommandRunner) doApprovePolicies(ctx command.ProjectConte
}
// User matches the author and prevent self approve is set to true
} else if isOwner && !ignorePolicy && ctx.User.Username == ctx.Pull.Author && policySet.PreventSelfApprove {
prjErr = multierror.Append(prjErr, fmt.Errorf("policy set: %s the author of pr %s matches the command commenter user %s - please contact another policy owners to approve failing policies", policySet.Name, ctx.Pull.Author, ctx.User.Username))
prjErr = errors.Join(prjErr, fmt.Errorf("policy set: %s the author of pr %s matches the command commenter user %s - please contact another policy owners to approve failing policies", policySet.Name, ctx.Pull.Author, ctx.User.Username))
// User is not authorized to approve policy set.
} else if !ignorePolicy {
prjErr = multierror.Append(prjErr, fmt.Errorf("policy set: %s user %s is not a policy owner - please contact policy owners to approve failing policies", policySet.Name, ctx.User.Username))
prjErr = errors.Join(prjErr, fmt.Errorf("policy set: %s user %s is not a policy owner - please contact policy owners to approve failing policies", policySet.Name, ctx.User.Username))
}
// Still bubble up this failure, even if policy set is not targeted.
if !policyStatus.Passed && (prjPolicyStatus[i].Approvals != policySet.ApproveCount) {
Expand Down Expand Up @@ -449,7 +448,7 @@ func (p *DefaultProjectCommandRunner) doPolicyCheck(ctx command.ProjectContext)
lockAttempt, err := p.Locker.TryLock(ctx.Log, ctx.Pull, ctx.User, ctx.Workspace, models.NewProject(ctx.Pull.BaseRepo.FullName, ctx.RepoRelDir, ctx.ProjectName), ctx.RepoLocksMode == valid.RepoLocksOnPlanMode)

if err != nil {
return nil, "", errors.Wrap(err, "acquiring lock")
return nil, "", fmt.Errorf("acquiring lock: %w", err)
}
if !lockAttempt.LockAcquired {
return nil, lockAttempt.LockFailureReason, nil
Expand Down Expand Up @@ -502,7 +501,7 @@ func (p *DefaultProjectCommandRunner) doPolicyCheck(ctx command.ProjectContext)
}
// Exclude errors for failed policies
if !strings.Contains(err.Error(), "some policies failed") {
errs = multierror.Append(errs, err)
errs = errors.Join(errs, err)
}
}

Expand Down Expand Up @@ -567,7 +566,7 @@ func (p *DefaultProjectCommandRunner) doPlan(ctx command.ProjectContext) (*model
// Acquire Atlantis lock for this repo/dir/workspace.
lockAttempt, err := p.Locker.TryLock(ctx.Log, ctx.Pull, ctx.User, ctx.Workspace, models.NewProject(ctx.Pull.BaseRepo.FullName, ctx.RepoRelDir, ctx.ProjectName), ctx.RepoLocksMode == valid.RepoLocksOnPlanMode)
if err != nil {
return nil, "", errors.Wrap(err, "acquiring lock")
return nil, "", fmt.Errorf("acquiring lock: %w", err)
}
if !lockAttempt.LockAcquired {
return nil, lockAttempt.LockFailureReason, nil
Expand Down Expand Up @@ -644,7 +643,7 @@ func (p *DefaultProjectCommandRunner) doApply(ctx command.ProjectContext) (apply
// Acquire Atlantis lock for this repo/dir/workspace.
lockAttempt, err := p.Locker.TryLock(ctx.Log, ctx.Pull, ctx.User, ctx.Workspace, models.NewProject(ctx.Pull.BaseRepo.FullName, ctx.RepoRelDir, ctx.ProjectName), ctx.RepoLocksMode == valid.RepoLocksOnApplyMode)
if err != nil {
return "", "", errors.Wrap(err, "acquiring lock")
return "", "", fmt.Errorf("acquiring lock: %w", err)
}
if !lockAttempt.LockAcquired {
return "", lockAttempt.LockFailureReason, nil
Expand Down Expand Up @@ -724,7 +723,7 @@ func (p *DefaultProjectCommandRunner) doImport(ctx command.ProjectContext) (out
// Acquire Atlantis lock for this repo/dir/workspace.
lockAttempt, err := p.Locker.TryLock(ctx.Log, ctx.Pull, ctx.User, ctx.Workspace, models.NewProject(ctx.Pull.BaseRepo.FullName, ctx.RepoRelDir, ctx.ProjectName), ctx.RepoLocksMode != valid.RepoLocksDisabledMode)
if err != nil {
return nil, "", errors.Wrap(err, "acquiring lock")
return nil, "", fmt.Errorf("acquiring lock: %w", err)
}
if !lockAttempt.LockAcquired {
return nil, lockAttempt.LockFailureReason, nil
Expand Down Expand Up @@ -765,7 +764,7 @@ func (p *DefaultProjectCommandRunner) doStateRm(ctx command.ProjectContext) (out
// Acquire Atlantis lock for this repo/dir/workspace.
lockAttempt, err := p.Locker.TryLock(ctx.Log, ctx.Pull, ctx.User, ctx.Workspace, models.NewProject(ctx.Pull.BaseRepo.FullName, ctx.RepoRelDir, ctx.ProjectName), ctx.RepoLocksMode != valid.RepoLocksDisabledMode)
if err != nil {
return nil, "", errors.Wrap(err, "acquiring lock")
return nil, "", fmt.Errorf("acquiring lock: %w", err)
}
if !lockAttempt.LockAcquired {
return nil, lockAttempt.LockFailureReason, nil
Expand Down