From 2ba8dc38fae1e885b6ce79fda27463b51470d852 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Sun, 27 Sep 2015 18:58:48 -0700 Subject: [PATCH] Switch to go-multierror MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It seems there are 4 locations left that use the `helper/multierror` package, where the rest is TF settled on the `hashicorp/go-multierror` package. Functionally this doesn’t change anything, so I suggest to delete the builtin version as it can only cause confusion (both packages have the same name, but are still different types according to Go’s type system. --- builtin/providers/aws/config.go | 2 +- .../aws/resource_aws_db_security_group.go | 2 +- .../providers/heroku/resource_heroku_app.go | 2 +- config/config.go | 2 +- helper/multierror/error.go | 54 ------------------ helper/multierror/error_test.go | 56 ------------------- 6 files changed, 4 insertions(+), 114 deletions(-) delete mode 100644 helper/multierror/error.go delete mode 100644 helper/multierror/error_test.go diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index a57c65c1b..369f0df37 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -5,7 +5,7 @@ import ( "log" "strings" - "github.com/hashicorp/terraform/helper/multierror" + "github.com/hashicorp/go-multierror" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" diff --git a/builtin/providers/aws/resource_aws_db_security_group.go b/builtin/providers/aws/resource_aws_db_security_group.go index 6932fc971..367400ae7 100644 --- a/builtin/providers/aws/resource_aws_db_security_group.go +++ b/builtin/providers/aws/resource_aws_db_security_group.go @@ -9,8 +9,8 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/rds" + "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform/helper/hashcode" - "github.com/hashicorp/terraform/helper/multierror" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" ) diff --git a/builtin/providers/heroku/resource_heroku_app.go b/builtin/providers/heroku/resource_heroku_app.go index 52954aa5d..4c2f3bf97 100644 --- a/builtin/providers/heroku/resource_heroku_app.go +++ b/builtin/providers/heroku/resource_heroku_app.go @@ -5,7 +5,7 @@ import ( "log" "github.com/cyberdelia/heroku-go/v3" - "github.com/hashicorp/terraform/helper/multierror" + "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform/helper/schema" ) diff --git a/config/config.go b/config/config.go index 811b77ec7..c088414da 100644 --- a/config/config.go +++ b/config/config.go @@ -8,10 +8,10 @@ import ( "strconv" "strings" + "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform/config/lang" "github.com/hashicorp/terraform/config/lang/ast" "github.com/hashicorp/terraform/flatmap" - "github.com/hashicorp/terraform/helper/multierror" "github.com/mitchellh/mapstructure" "github.com/mitchellh/reflectwalk" ) diff --git a/helper/multierror/error.go b/helper/multierror/error.go deleted file mode 100644 index ae21e4366..000000000 --- a/helper/multierror/error.go +++ /dev/null @@ -1,54 +0,0 @@ -package multierror - -import ( - "fmt" - "strings" -) - -// Error is an error type to track multiple errors. This is used to -// accumulate errors in cases such as configuration parsing, and returning -// them as a single error. -type Error struct { - Errors []error -} - -func (e *Error) Error() string { - points := make([]string, len(e.Errors)) - for i, err := range e.Errors { - points[i] = fmt.Sprintf("* %s", err) - } - - return fmt.Sprintf( - "%d error(s) occurred:\n\n%s", - len(e.Errors), strings.Join(points, "\n")) -} - -func (e *Error) GoString() string { - return fmt.Sprintf("*%#v", *e) -} - -// ErrorAppend is a helper function that will append more errors -// onto an Error in order to create a larger multi-error. If the -// original error is not an Error, it will be turned into one. -func ErrorAppend(err error, errs ...error) *Error { - if err == nil { - err = new(Error) - } - - switch err := err.(type) { - case *Error: - if err == nil { - err = new(Error) - } - - err.Errors = append(err.Errors, errs...) - return err - default: - newErrs := make([]error, len(errs)+1) - newErrs[0] = err - copy(newErrs[1:], errs) - return &Error{ - Errors: newErrs, - } - } -} diff --git a/helper/multierror/error_test.go b/helper/multierror/error_test.go deleted file mode 100644 index 207c00465..000000000 --- a/helper/multierror/error_test.go +++ /dev/null @@ -1,56 +0,0 @@ -package multierror - -import ( - "errors" - "testing" -) - -func TestError_Impl(t *testing.T) { - var raw interface{} - raw = &Error{} - if _, ok := raw.(error); !ok { - t.Fatal("Error must implement error") - } -} - -func TestErrorError(t *testing.T) { - expected := `2 error(s) occurred: - -* foo -* bar` - - errors := []error{ - errors.New("foo"), - errors.New("bar"), - } - - multi := &Error{errors} - if multi.Error() != expected { - t.Fatalf("bad: %s", multi.Error()) - } -} - -func TestErrorAppend_Error(t *testing.T) { - original := &Error{ - Errors: []error{errors.New("foo")}, - } - - result := ErrorAppend(original, errors.New("bar")) - if len(result.Errors) != 2 { - t.Fatalf("wrong len: %d", len(result.Errors)) - } - - original = &Error{} - result = ErrorAppend(original, errors.New("bar")) - if len(result.Errors) != 1 { - t.Fatalf("wrong len: %d", len(result.Errors)) - } -} - -func TestErrorAppend_NonError(t *testing.T) { - original := errors.New("foo") - result := ErrorAppend(original, errors.New("bar")) - if len(result.Errors) != 2 { - t.Fatalf("wrong len: %d", len(result.Errors)) - } -}