From d978deb8c734987672e2a8ff29dc0f3e32e5ff6d Mon Sep 17 00:00:00 2001 From: Stephan Renatus Date: Tue, 27 Feb 2024 11:09:23 +0100 Subject: [PATCH] cleanup: use errors.Join Signed-off-by: Stephan Renatus --- internal/errors/join.go | 53 ---------------------------------- internal/errors/join_go1.20.go | 7 ----- plugins/discovery/discovery.go | 2 +- plugins/plugins.go | 2 +- server/certs.go | 2 +- 5 files changed, 3 insertions(+), 63 deletions(-) delete mode 100644 internal/errors/join.go delete mode 100644 internal/errors/join_go1.20.go diff --git a/internal/errors/join.go b/internal/errors/join.go deleted file mode 100644 index 8d8e1f301d..0000000000 --- a/internal/errors/join.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2022 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build !go1.20 - -package errors - -// Join returns an error that wraps the given errors. -// Any nil error values are discarded. -// Join returns nil if errs contains no non-nil values. -// The error formats as the concatenation of the strings obtained -// by calling the Error method of each element of errs, with a newline -// between each string. -func Join(errs ...error) error { - n := 0 - for _, err := range errs { - if err != nil { - n++ - } - } - if n == 0 { - return nil - } - e := &joinError{ - errs: make([]error, 0, n), - } - for _, err := range errs { - if err != nil { - e.errs = append(e.errs, err) - } - } - return e -} - -type joinError struct { - errs []error -} - -func (e *joinError) Error() string { - var b []byte - for i, err := range e.errs { - if i > 0 { - b = append(b, '\n') - } - b = append(b, err.Error()...) - } - return string(b) -} - -func (e *joinError) Unwrap() []error { - return e.errs -} diff --git a/internal/errors/join_go1.20.go b/internal/errors/join_go1.20.go deleted file mode 100644 index 666f3c783e..0000000000 --- a/internal/errors/join_go1.20.go +++ /dev/null @@ -1,7 +0,0 @@ -//go:build go1.20 - -package errors - -import "errors" - -var Join = errors.Join diff --git a/plugins/discovery/discovery.go b/plugins/discovery/discovery.go index ae26ab36b5..02e3d633ae 100644 --- a/plugins/discovery/discovery.go +++ b/plugins/discovery/discovery.go @@ -8,6 +8,7 @@ package discovery import ( "context" "encoding/json" + "errors" "fmt" "io" "os" @@ -22,7 +23,6 @@ import ( "github.com/open-policy-agent/opa/hooks" bundleUtils "github.com/open-policy-agent/opa/internal/bundle" cfg "github.com/open-policy-agent/opa/internal/config" - "github.com/open-policy-agent/opa/internal/errors" "github.com/open-policy-agent/opa/keys" "github.com/open-policy-agent/opa/logging" "github.com/open-policy-agent/opa/metrics" diff --git a/plugins/plugins.go b/plugins/plugins.go index 283fcc4591..0859305952 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -7,6 +7,7 @@ package plugins import ( "context" + "errors" "fmt" mr "math/rand" "sync" @@ -24,7 +25,6 @@ import ( "github.com/open-policy-agent/opa/hooks" bundleUtils "github.com/open-policy-agent/opa/internal/bundle" cfg "github.com/open-policy-agent/opa/internal/config" - "github.com/open-policy-agent/opa/internal/errors" initload "github.com/open-policy-agent/opa/internal/runtime/init" "github.com/open-policy-agent/opa/keys" "github.com/open-policy-agent/opa/loader" diff --git a/server/certs.go b/server/certs.go index 86876f0982..98cfafcb3e 100644 --- a/server/certs.go +++ b/server/certs.go @@ -9,6 +9,7 @@ import ( "crypto/sha256" "crypto/tls" "crypto/x509" + "errors" "fmt" "io" "os" @@ -16,7 +17,6 @@ import ( "github.com/fsnotify/fsnotify" - "github.com/open-policy-agent/opa/internal/errors" "github.com/open-policy-agent/opa/internal/pathwatcher" "github.com/open-policy-agent/opa/logging" )