diff --git a/go.mod b/go.mod index 0572c67157..94e21fd572 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/google/go-cmp v0.5.9 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/go-hclog v1.5.0 - github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-plugin v1.5.1 github.com/hashicorp/go-uuid v1.0.3 github.com/hashicorp/go-version v1.6.0 @@ -35,6 +34,7 @@ require ( github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/terraform-registry-address v0.2.2 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect diff --git a/helper/customdiff/compose.go b/helper/customdiff/compose.go index 0da82ce49e..e4b5a2fdd0 100644 --- a/helper/customdiff/compose.go +++ b/helper/customdiff/compose.go @@ -5,8 +5,7 @@ package customdiff import ( "context" - - "github.com/hashicorp/go-multierror" + "errors" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -48,14 +47,14 @@ import ( // } func All(funcs ...schema.CustomizeDiffFunc) schema.CustomizeDiffFunc { return func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error { - var err error + var errs []error for _, f := range funcs { thisErr := f(ctx, d, meta) if thisErr != nil { - err = multierror.Append(err, thisErr) + errs = append(errs, thisErr) } } - return err + return errors.Join(errs...) } } diff --git a/helper/customdiff/compose_test.go b/helper/customdiff/compose_test.go index 96b961420e..374c0ca435 100644 --- a/helper/customdiff/compose_test.go +++ b/helper/customdiff/compose_test.go @@ -6,7 +6,6 @@ package customdiff import ( "context" "errors" - "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -14,13 +13,15 @@ import ( func TestAll(t *testing.T) { var aCalled, bCalled, cCalled bool + aErr := errors.New("A bad") + cErr := errors.New("C bad") provider := testProvider( map[string]*schema.Schema{}, All( func(_ context.Context, d *schema.ResourceDiff, meta interface{}) error { aCalled = true - return errors.New("A bad") + return aErr }, func(_ context.Context, d *schema.ResourceDiff, meta interface{}) error { bCalled = true @@ -28,7 +29,7 @@ func TestAll(t *testing.T) { }, func(_ context.Context, d *schema.ResourceDiff, meta interface{}) error { cCalled = true - return errors.New("C bad") + return cErr }, ), ) @@ -46,11 +47,11 @@ func TestAll(t *testing.T) { if err == nil { t.Fatal("Diff succeeded; want error") } - if s, sub := err.Error(), "* A bad"; !strings.Contains(s, sub) { - t.Errorf("Missing substring %q in error message %q", sub, s) + if !errors.Is(err, aErr) { + t.Errorf("Missing substring %q in error message %q", aErr, err) } - if s, sub := err.Error(), "* C bad"; !strings.Contains(s, sub) { - t.Errorf("Missing substring %q in error message %q", sub, s) + if !errors.Is(err, cErr) { + t.Errorf("Missing substring %q in error message %q", cErr, err) } if !aCalled { diff --git a/helper/resource/testing.go b/helper/resource/testing.go index a14eede9e5..9bde8e22aa 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -15,7 +15,6 @@ import ( "strings" "time" - "github.com/hashicorp/go-multierror" "github.com/mitchellh/go-testing-interface" "github.com/hashicorp/terraform-plugin-go/tfprotov5" @@ -836,15 +835,15 @@ func ComposeTestCheckFunc(fs ...TestCheckFunc) TestCheckFunc { // TestCheckFuncs and aggregates failures. func ComposeAggregateTestCheckFunc(fs ...TestCheckFunc) TestCheckFunc { return func(s *terraform.State) error { - var result *multierror.Error + var result []error for i, f := range fs { if err := f(s); err != nil { - result = multierror.Append(result, fmt.Errorf("Check %d/%d error: %s", i+1, len(fs), err)) + result = append(result, fmt.Errorf("Check %d/%d error: %w", i+1, len(fs), err)) } } - return result.ErrorOrNil() + return errors.Join(result...) } } diff --git a/helper/resource/testing_test.go b/helper/resource/testing_test.go index 9f697af910..0b0a87e049 100644 --- a/helper/resource/testing_test.go +++ b/helper/resource/testing_test.go @@ -13,7 +13,6 @@ import ( "strings" "testing" - "github.com/hashicorp/go-multierror" testinginterface "github.com/mitchellh/go-testing-interface" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -88,26 +87,27 @@ func TestParallelTest(t *testing.T) { } func TestComposeAggregateTestCheckFunc(t *testing.T) { + err1 := errors.New("Error 1") check1 := func(s *terraform.State) error { - return errors.New("Error 1") + return err1 } + err2 := errors.New("Error 2") check2 := func(s *terraform.State) error { - return errors.New("Error 2") + return err2 } f := ComposeAggregateTestCheckFunc(check1, check2) err := f(nil) if err == nil { - t.Fatalf("Expected errors") + t.Fatal("expected error, got none") } - multi := err.(*multierror.Error) - if !strings.Contains(multi.Errors[0].Error(), "Error 1") { - t.Fatalf("Expected Error 1, Got %s", multi.Errors[0]) + if !errors.Is(err, err1) { + t.Errorf("expected %s, got: %s", err1, err) } - if !strings.Contains(multi.Errors[1].Error(), "Error 2") { - t.Fatalf("Expected Error 2, Got %s", multi.Errors[1]) + if !errors.Is(err, err2) { + t.Errorf("expected %s, got: %s", err2, err) } } diff --git a/helper/schema/provider.go b/helper/schema/provider.go index 75e1a7c42e..25055548e8 100644 --- a/helper/schema/provider.go +++ b/helper/schema/provider.go @@ -12,8 +12,6 @@ import ( "sort" "strings" - "github.com/hashicorp/go-multierror" - "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/internal/configs/configschema" @@ -130,10 +128,10 @@ func (p *Provider) InternalValidate() error { return errors.New("ConfigureFunc and ConfigureContextFunc must not both be set") } - var validationErrors error + var validationErrors []error sm := schemaMap(p.Schema) if err := sm.InternalValidate(sm); err != nil { - validationErrors = multierror.Append(validationErrors, err) + validationErrors = append(validationErrors, err) } // Provider-specific checks @@ -145,17 +143,17 @@ func (p *Provider) InternalValidate() error { for k, r := range p.ResourcesMap { if err := r.InternalValidate(nil, true); err != nil { - validationErrors = multierror.Append(validationErrors, fmt.Errorf("resource %s: %s", k, err)) + validationErrors = append(validationErrors, fmt.Errorf("resource %s: %s", k, err)) } } for k, r := range p.DataSourcesMap { if err := r.InternalValidate(nil, false); err != nil { - validationErrors = multierror.Append(validationErrors, fmt.Errorf("data source %s: %s", k, err)) + validationErrors = append(validationErrors, fmt.Errorf("data source %s: %s", k, err)) } } - return validationErrors + return errors.Join(validationErrors...) } func isReservedProviderFieldName(name string) bool { diff --git a/internal/diagutils/diagutils.go b/internal/diagutils/diagutils.go index d587ebba59..c686e6386a 100644 --- a/internal/diagutils/diagutils.go +++ b/internal/diagutils/diagutils.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" - "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" ) @@ -28,7 +27,7 @@ func (diags ErrorDiags) Errors() []error { } func (diags ErrorDiags) Error() string { - return multierror.ListFormatFunc(diags.Errors()) + return errors.Join(diags.Errors()...).Error() } type WarningDiags diag.Diagnostics diff --git a/terraform/state.go b/terraform/state.go index 9357070b40..7d2179358a 100644 --- a/terraform/state.go +++ b/terraform/state.go @@ -7,6 +7,7 @@ import ( "bufio" "bytes" "encoding/json" + "errors" "fmt" "log" "os" @@ -17,7 +18,6 @@ import ( "sync" "github.com/hashicorp/go-cty/cty" - "github.com/hashicorp/go-multierror" "github.com/hashicorp/go-uuid" "github.com/mitchellh/copystructure" @@ -287,7 +287,7 @@ func (s *State) Validate() error { s.Lock() defer s.Unlock() - var result error + var result []error // !!!! FOR DEVELOPERS !!!! // @@ -309,7 +309,7 @@ func (s *State) Validate() error { key := strings.Join(ms.Path, ".") if _, ok := found[key]; ok { - result = multierror.Append(result, fmt.Errorf( + result = append(result, fmt.Errorf( strings.TrimSpace(stateValidateErrMultiModule), key)) continue } @@ -318,7 +318,7 @@ func (s *State) Validate() error { } } - return result + return errors.Join(result...) } // Remove removes the item in the state at the given address, returning