Switch to go-multierror

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.
This commit is contained in:
Sander van Harmelen 2015-09-27 18:58:48 -07:00
parent 6bd40a7bf4
commit 2ba8dc38fa
6 changed files with 4 additions and 114 deletions

View File

@ -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"

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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,
}
}
}

View File

@ -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))
}
}