Merge #3336: Remove local multierror package.
Instead, use ``github.com/hashicorp/go-multierror``.
This commit is contained in:
commit
3fde993978
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue