From d9c3afc4cfde07ff49fc6cdb3ba6cde922a692ec Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Tue, 21 Dec 2021 09:58:02 -0800 Subject: [PATCH] Remove deprecated `consumererror.Combine` Signed-off-by: Bogdan Drutu --- consumer/consumererror/combine.go | 74 ----------------- consumer/consumererror/combine_test.go | 111 ------------------------- 2 files changed, 185 deletions(-) delete mode 100644 consumer/consumererror/combine.go delete mode 100644 consumer/consumererror/combine_test.go diff --git a/consumer/consumererror/combine.go b/consumer/consumererror/combine.go deleted file mode 100644 index cd53b9e93324..000000000000 --- a/consumer/consumererror/combine.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package consumererror // import "go.opentelemetry.io/collector/consumer/consumererror" - -import ( - "errors" - "strings" -) - -type combined []error - -func (c combined) Error() string { - if len(c) == 0 { - return "[]" - } - var sb strings.Builder - sb.WriteString("[") - sb.WriteString(c[0].Error()) - for _, err := range c[1:] { - sb.WriteString("; ") - sb.WriteString(err.Error()) - } - sb.WriteString("]") - return sb.String() -} - -func (c combined) Is(target error) bool { - for _, err := range c { - if errors.Is(err, target) { - return true - } - } - return false -} - -func (c combined) As(target interface{}) bool { - for _, err := range c { - if errors.As(err, target) { - return true - } - } - return false -} - -// Combine converts a list of errors into one error. -// -// Deprecated: Use alternative modules like "go.uber.org/multierr" -func Combine(errs []error) error { - switch len(errs) { - case 0: - return nil - case 1: - return errs[0] - } - result := make([]error, 0, len(errs)) - for _, err := range errs { - if err != nil { - result = append(result, err) - } - } - return combined(result) -} diff --git a/consumer/consumererror/combine_test.go b/consumer/consumererror/combine_test.go deleted file mode 100644 index 8fe6ddaf722a..000000000000 --- a/consumer/consumererror/combine_test.go +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package consumererror - -import ( - "errors" - "fmt" - "io" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestCombine(t *testing.T) { - t.Parallel() - - testCases := []struct { - errors []error - expected string - expectNil bool - expectedPermanent bool - }{ - { - errors: []error{}, - expectNil: true, - }, - { - errors: []error{ - fmt.Errorf("foo"), - }, - expected: "foo", - }, - { - errors: []error{ - fmt.Errorf("foo"), - fmt.Errorf("bar"), - }, - expected: "[foo; bar]", - }, - { - errors: []error{ - fmt.Errorf("foo"), - fmt.Errorf("bar"), - NewPermanent(fmt.Errorf("permanent"))}, - expected: "[foo; bar; Permanent error: permanent]", - }, - { - errors: []error{ - errors.New("foo"), - errors.New("bar"), - nil, - }, - expected: "[foo; bar]", - }, - { - errors: []error{ - errors.New("foo"), - errors.New("bar"), - Combine([]error{ - errors.New("foo"), - errors.New("bar"), - }), - }, - expected: "[foo; bar; [foo; bar]]", - }, - } - - for _, tc := range testCases { - got := Combine(tc.errors) - if (got == nil) != tc.expectNil { - t.Errorf("Combine(%v) == nil? Got: %t. Want: %t", tc.errors, got == nil, tc.expectNil) - } - if got != nil && tc.expected != got.Error() { - t.Errorf("Combine(%v) = %q. Want: %q", tc.errors, got, tc.expected) - } - if tc.expectedPermanent && !IsPermanent(got) { - t.Errorf("Combine(%v) = %q. Want: consumererror.permanent", tc.errors, got) - } - } -} - -func TestCombineContainsError(t *testing.T) { - t.Parallel() - - testCases := []struct { - contains error - err error - }{ - {contains: io.EOF, err: Combine([]error{errors.New("invalid entry"), io.EOF})}, - {contains: io.EOF, err: Combine([]error{errors.New("invalid entry"), NewPermanent(io.EOF)})}, - {contains: io.EOF, err: Combine([]error{errors.New("foo"), errors.New("bar"), Combine([]error{errors.New("xyz"), io.EOF})})}, - } - - for _, tc := range testCases { - assert.ErrorIs(t, tc.err, tc.contains, "Must have the expected error") - } - - assert.NotErrorIs(t, Combine([]error{errors.New("invalid"), errors.New("foo")}), io.EOF, "Must return false when error does not exist within error") -}