diff --git a/NOTICE.txt b/NOTICE.txt index ec5d292a179..91cf601eeec 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -8425,39 +8425,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --------------------------------------------------------------------------------- -Dependency : github.com/pkg/errors -Version: v0.9.1 -Licence type (autodetected): BSD-2-Clause --------------------------------------------------------------------------------- - -Contents of probable licence file $GOMODCACHE/github.com/pkg/errors@v0.9.1/LICENSE: - -Copyright (c) 2015, Dave Cheney -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -------------------------------------------------------------------------------- Dependency : github.com/rcrowley/go-metrics Version: v0.0.0-20201227073835-cf1acfcdf475 @@ -47211,6 +47178,39 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-------------------------------------------------------------------------------- +Dependency : github.com/pkg/errors +Version: v0.9.1 +Licence type (autodetected): BSD-2-Clause +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/github.com/pkg/errors@v0.9.1/LICENSE: + +Copyright (c) 2015, Dave Cheney +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + -------------------------------------------------------------------------------- Dependency : github.com/pmezard/go-difflib Version: v1.0.1-0.20181226105442-5d4384ee4fb2 diff --git a/dev-tools/mage/build.go b/dev-tools/mage/build.go index 6f250faa3c0..e8cb5358702 100644 --- a/dev-tools/mage/build.go +++ b/dev-tools/mage/build.go @@ -5,6 +5,7 @@ package mage import ( + "errors" "fmt" "go/build" "log" @@ -14,7 +15,8 @@ import ( "github.com/josephspurrier/goversioninfo" "github.com/magefile/mage/sh" - "github.com/pkg/errors" + "golang.org/x/text/cases" + "golang.org/x/text/language" ) // BuildArgs are the arguments used for the "build" target and they define how @@ -111,7 +113,7 @@ func DefaultGolangCrossBuildArgs() BuildArgs { func GolangCrossBuild(params BuildArgs) error { if os.Getenv("GOLANG_CROSSBUILD") != "1" { return errors.New("Use the crossBuild target. golangCrossBuild can " + - "only be executed within the golang-crossbuild docker environment.") + "only be executed within the golang-crossbuild docker environment") } defer DockerChown(filepath.Join(params.OutputDir, params.Name+binaryExtension(GOOS))) @@ -180,7 +182,7 @@ func Build(params BuildArgs) error { log.Println("Generating a .syso containing Windows file metadata.") syso, err := MakeWindowsSysoFile() if err != nil { - return errors.Wrap(err, "failed generating Windows .syso metadata file") + return fmt.Errorf("failed generating Windows .syso metadata file: %w", err) } defer os.Remove(syso) } @@ -219,7 +221,7 @@ func MakeWindowsSysoFile() (string, error) { }, StringFileInfo: goversioninfo.StringFileInfo{ CompanyName: BeatVendor, - ProductName: strings.Title(BeatName), + ProductName: cases.Title(language.Und, cases.NoLower).String(BeatName), ProductVersion: version, FileVersion: version, FileDescription: BeatDescription, @@ -233,7 +235,7 @@ func MakeWindowsSysoFile() (string, error) { vi.Walk() sysoFile := BeatName + "_windows_" + GOARCH + ".syso" if err = vi.WriteSyso(sysoFile, GOARCH); err != nil { - return "", errors.Wrap(err, "failed to generate syso file with Windows metadata") + return "", fmt.Errorf("failed to generate syso file with Windows metadata: %w", err) } return sysoFile, nil } diff --git a/dev-tools/mage/config.go b/dev-tools/mage/config.go index 2c9763aa851..286ce9dbaec 100644 --- a/dev-tools/mage/config.go +++ b/dev-tools/mage/config.go @@ -14,15 +14,6 @@ import ( "text/template" "github.com/magefile/mage/mg" - - "github.com/pkg/errors" -) - -// Paths to generated config file templates. -var ( - shortTemplate = filepath.Join("build", BeatName+".yml.tmpl") - referenceTemplate = filepath.Join("build", BeatName+".reference.yml.tmpl") - dockerTemplate = filepath.Join("build", BeatName+".docker.yml.tmpl") ) // ConfigFileType is a bitset that indicates what types of config files to @@ -67,7 +58,7 @@ func Config(types ConfigFileType, args ConfigFileParams, targetDir string) error if types.IsShort() { file := filepath.Join(targetDir, BeatName+".yml") if err := makeConfigTemplate(file, 0600, args, ShortConfigType); err != nil { - return errors.Wrap(err, "failed making short config") + return fmt.Errorf("failed making short config: %w", err) } } @@ -75,7 +66,7 @@ func Config(types ConfigFileType, args ConfigFileParams, targetDir string) error if types.IsReference() { file := filepath.Join(targetDir, BeatName+".reference.yml") if err := makeConfigTemplate(file, 0644, args, ReferenceConfigType); err != nil { - return errors.Wrap(err, "failed making reference config") + return fmt.Errorf("failed making reference config: %w", err) } } @@ -83,7 +74,7 @@ func Config(types ConfigFileType, args ConfigFileParams, targetDir string) error if types.IsDocker() { file := filepath.Join(targetDir, BeatName+".docker.yml") if err := makeConfigTemplate(file, 0600, args, DockerConfigType); err != nil { - return errors.Wrap(err, "failed making docker config") + return fmt.Errorf("failed making docker config: %w", err) } } @@ -105,7 +96,7 @@ func makeConfigTemplate(destination string, mode os.FileMode, confParams ConfigF confFile = confParams.Docker tmplParams = map[string]interface{}{"Docker": true} default: - panic(errors.Errorf("Invalid config file type: %v", typ)) + panic(fmt.Errorf("invalid config file type: %v", typ)) } // Build the dependencies. @@ -154,18 +145,18 @@ func makeConfigTemplate(destination string, mode os.FileMode, confParams ConfigF var err error for _, templateGlob := range confParams.Templates { if tmpl, err = tmpl.ParseGlob(templateGlob); err != nil { - return errors.Wrapf(err, "failed to parse config templates in %q", templateGlob) + return fmt.Errorf("failed to parse config templates in %q: %w", templateGlob, err) } } data, err := os.ReadFile(confFile.Template) if err != nil { - return errors.Wrapf(err, "failed to read config template %q", confFile.Template) + return fmt.Errorf("failed to read config template %q: %w", confFile.Template, err) } tmpl, err = tmpl.Parse(string(data)) if err != nil { - return errors.Wrap(err, "failed to parse template") + return fmt.Errorf("failed to parse template: %w", err) } out, err := os.OpenFile(CreateDir(destination), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, mode) @@ -175,7 +166,7 @@ func makeConfigTemplate(destination string, mode os.FileMode, confParams ConfigF defer out.Close() if err = tmpl.Execute(out, EnvMap(params)); err != nil { - return errors.Wrapf(err, "failed building %v", destination) + return fmt.Errorf("failed building %v: %w", destination, err) } return nil diff --git a/dev-tools/mage/fmt.go b/dev-tools/mage/fmt.go index dda355683cd..9973f487127 100644 --- a/dev-tools/mage/fmt.go +++ b/dev-tools/mage/fmt.go @@ -11,7 +11,6 @@ import ( "github.com/magefile/mage/mg" "github.com/magefile/mage/sh" - "github.com/pkg/errors" "github.com/elastic/elastic-agent/dev-tools/mage/gotool" ) @@ -83,7 +82,7 @@ func AddLicenseHeaders() error { case "Elasticv2", "Elastic License 2.0": license = "Elasticv2" default: - return errors.Errorf("unknown license type %v", BeatLicense) + return fmt.Errorf("unknown license type %s", BeatLicense) } licenser := gotool.Licenser diff --git a/dev-tools/mage/gomod.go b/dev-tools/mage/gomod.go index f5fe5cbd970..fdcb46792fb 100644 --- a/dev-tools/mage/gomod.go +++ b/dev-tools/mage/gomod.go @@ -5,11 +5,10 @@ package mage import ( + "fmt" "os" "path/filepath" - "github.com/pkg/errors" - "github.com/elastic/elastic-agent/dev-tools/mage/gotool" ) @@ -25,7 +24,7 @@ func CopyFilesToVendor(vendorFolder string, modulesToCopy []CopyModule) error { for _, p := range modulesToCopy { path, err := gotool.ListModuleCacheDir(p.Name) if err != nil { - return errors.Wrapf(err, "error while looking up cached dir of module: %s", p.Name) + return fmt.Errorf("error while looking up cached dir of module: %s: %w", p.Name, err) } for _, f := range p.FilesToCopy { @@ -34,7 +33,7 @@ func CopyFilesToVendor(vendorFolder string, modulesToCopy []CopyModule) error { copyTask := &CopyTask{Source: from, Dest: to, Mode: 0600, DirMode: os.ModeDir | 0750} err = copyTask.Execute() if err != nil { - return errors.Wrapf(err, "error while copying file from %s to %s", from, to) + return fmt.Errorf("error while copying file from %s to %s: %w", from, to, err) } } } diff --git a/dev-tools/mage/integtest_docker.go b/dev-tools/mage/integtest_docker.go index 81c8716dcfc..de2bdf9b59c 100644 --- a/dev-tools/mage/integtest_docker.go +++ b/dev-tools/mage/integtest_docker.go @@ -16,8 +16,6 @@ import ( "sync" "time" - "github.com/pkg/errors" - "github.com/magefile/mage/mg" "github.com/magefile/mage/sh" ) @@ -230,12 +228,12 @@ func integTestDockerComposeEnvVars() (map[string]string, error) { func dockerComposeProjectName() string { commit, err := CommitHash() if err != nil { - panic(errors.Wrap(err, "failed to construct docker compose project name")) + panic(fmt.Errorf("failed to construct docker compose project name: %w", err)) } version, err := BeatQualifiedVersion() if err != nil { - panic(errors.Wrap(err, "failed to construct docker compose project name")) + panic(fmt.Errorf("failed to construct docker compose project name: %w", err)) } version = strings.NewReplacer(".", "_").Replace(version) @@ -278,9 +276,9 @@ func dockerComposeBuildImages() error { "docker-compose", args..., ) - // This sleep is to avoid hitting the docker build issues when resources are not available. if err != nil { fmt.Println(">> Building docker images again") + //nolint:staticcheck // This sleep is to avoid hitting the docker build issues when resources are not available. time.Sleep(10) _, err = sh.Exec( composeEnv, diff --git a/dev-tools/mage/kubernetes/kuberemote.go b/dev-tools/mage/kubernetes/kuberemote.go index 4c6ad6fdcdf..6174a3b51f3 100644 --- a/dev-tools/mage/kubernetes/kuberemote.go +++ b/dev-tools/mage/kubernetes/kuberemote.go @@ -22,7 +22,6 @@ import ( "strings" "time" - "github.com/pkg/errors" "golang.org/x/crypto/ssh" apiv1 "k8s.io/api/core/v1" @@ -84,7 +83,7 @@ func NewKubeRemote(kubeconfig string, namespace string, name string, workDir str // Run runs the command remotely on the kubernetes cluster. func (r *KubeRemote) Run(env map[string]string, stdout io.Writer, stderr io.Writer, args ...string) error { if err := r.syncSSHKey(); err != nil { - return errors.Wrap(err, "failed to sync SSH secret") + return fmt.Errorf("failed to sync SSH secret: %w", err) } defer r.deleteSSHKey() if err := r.syncServiceAccount(); err != nil { @@ -93,21 +92,21 @@ func (r *KubeRemote) Run(env map[string]string, stdout io.Writer, stderr io.Writ defer r.deleteServiceAccount() _, err := r.createPod(env, args...) if err != nil { - return errors.Wrap(err, "failed to create execute pod") + return fmt.Errorf("failed to create execute pod: %w", err) } defer r.deletePod() // wait for SSH to be up inside the init container. _, err = r.waitForPod(5*time.Minute, podInitReady) if err != nil { - return errors.Wrap(err, "execute pod init container never started") + return fmt.Errorf("execute pod init container never started: %w", err) } time.Sleep(1 * time.Second) // SSH inside of container can take a moment // forward the SSH port so rsync can be ran. randomPort, err := getFreePort() if err != nil { - return errors.Wrap(err, "failed to find a free port") + return fmt.Errorf("failed to find a free port: %w", err) } stopChannel := make(chan struct{}, 1) readyChannel := make(chan struct{}, 1) @@ -115,11 +114,14 @@ func (r *KubeRemote) Run(env map[string]string, stdout io.Writer, stderr io.Writ if err != nil { return err } + //nolint:errcheck // ignore error go f.ForwardPorts() <-readyChannel // perform the rsync - r.rsync(randomPort, stderr, stderr) + if err := r.rsync(randomPort, stderr, stderr); err != nil { + return err + } // stop port forwarding close(stopChannel) @@ -127,19 +129,19 @@ func (r *KubeRemote) Run(env map[string]string, stdout io.Writer, stderr io.Writ // wait for exec container to be running _, err = r.waitForPod(5*time.Minute, containerRunning("exec")) if err != nil { - return errors.Wrap(err, "execute pod container never started") + return fmt.Errorf("execute pod container never started: %w", err) } // stream the logs of the container err = r.streamLogs("exec", stdout) if err != nil { - return errors.Wrap(err, "failed to stream the logs") + return fmt.Errorf("failed to stream the logs: %w", err) } // wait for exec container to be completely done pod, err := r.waitForPod(30*time.Second, podDone) if err != nil { - return errors.Wrap(err, "execute pod didn't terminate after 30 seconds of log stream") + return fmt.Errorf("execute pod didn't terminate after 30 seconds of log stream: %w", err) } // return error on failure @@ -186,18 +188,18 @@ func (r *KubeRemote) syncServiceAccount() error { createServiceAccountManifest(r.svcAccName), metav1.CreateOptions{}) if err != nil { - return errors.Wrap(err, "failed to create service account") + return fmt.Errorf("failed to create service account: %w", err) } _, err = r.cs.RbacV1().ClusterRoles().Create(ctx, createClusterRoleManifest(r.name), metav1.CreateOptions{}) if err != nil { - return errors.Wrap(err, "failed to create cluster role") + return fmt.Errorf("failed to create cluster role: %w", err) } _, err = r.cs.RbacV1().ClusterRoleBindings().Create( ctx, createClusterRoleBindingManifest(r.name, r.namespace, r.svcAccName), metav1.CreateOptions{}) if err != nil { - return errors.Wrap(err, "failed to create cluster role binding") + return fmt.Errorf("failed to create cluster role binding: %w", err) } return nil } @@ -246,7 +248,7 @@ func (r *KubeRemote) portForward(ports []string, stopChannel, readyChannel chan } path := fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/portforward", r.namespace, r.name) - hostIP := strings.TrimLeft(r.cfg.Host, "https://") + hostIP := strings.TrimPrefix(r.cfg.Host, "https://") serverURL := url.URL{Scheme: "https", Path: path, Host: hostIP} dialer := spdy.NewDialer(upgrader, &http.Client{Transport: roundTripper}, http.MethodPost, &serverURL) return portforward.New(dialer, ports, stopChannel, readyChannel, stdout, stderr) @@ -530,7 +532,7 @@ func isInitContainersReady(pod *apiv1.Pod) bool { } func isScheduled(pod *apiv1.Pod) bool { - if &pod.Status != nil && len(pod.Status.Conditions) > 0 { + if len(pod.Status.Conditions) > 0 { for _, condition := range pod.Status.Conditions { if condition.Type == apiv1.PodScheduled && condition.Status == apiv1.ConditionTrue { @@ -542,18 +544,15 @@ func isScheduled(pod *apiv1.Pod) bool { } func isInitContainersRunning(pod *apiv1.Pod) bool { - if &pod.Status != nil { - if len(pod.Spec.InitContainers) != len(pod.Status.InitContainerStatuses) { + if len(pod.Spec.InitContainers) != len(pod.Status.InitContainerStatuses) { + return false + } + for _, status := range pod.Status.InitContainerStatuses { + if status.State.Running == nil { return false } - for _, status := range pod.Status.InitContainerStatuses { - if status.State.Running == nil { - return false - } - } - return true } - return false + return true } func containerRunning(containerName string) func(watch.Event) (bool, error) { @@ -585,7 +584,7 @@ func isContainerRunning(pod *apiv1.Pod, containerName string) (bool, error) { } else if status.State.Terminated != nil { return false, nil } else { - return false, fmt.Errorf("Unknown container state") + return false, fmt.Errorf("unknown container state") } } } @@ -609,7 +608,10 @@ func podDone(event watch.Event) (bool, error) { func createTempFile(content []byte) (string, error) { randBytes := make([]byte, 16) - rand.Read(randBytes) + _, err := rand.Read(randBytes) + if err != nil { + return "", err + } tmpfile, err := os.CreateTemp("", hex.EncodeToString(randBytes)) if err != nil { return "", err diff --git a/dev-tools/mage/kubernetes/kubernetes.go b/dev-tools/mage/kubernetes/kubernetes.go index f8a6f7c8a0a..4367efc6940 100644 --- a/dev-tools/mage/kubernetes/kubernetes.go +++ b/dev-tools/mage/kubernetes/kubernetes.go @@ -15,7 +15,6 @@ import ( "time" "github.com/magefile/mage/mg" - "github.com/pkg/errors" "github.com/elastic/elastic-agent/dev-tools/mage" ) @@ -93,14 +92,14 @@ func (d *IntegrationTester) Test(dir string, mageTarget string, env map[string]s // Apply the manifest from the dir. This is the requirements for the tests that will // run inside the cluster. if err := KubectlApply(env, stdOut, stdErr, manifestPath); err != nil { - return errors.Wrapf(err, "failed to apply manifest %s", manifestPath) + return fmt.Errorf("failed to apply manifest %s: %w", manifestPath, err) } defer func() { if mg.Verbose() { fmt.Println(">> Deleting module manifest from cluster...") } if err := KubectlDelete(env, stdOut, stdErr, manifestPath); err != nil { - log.Printf("%s", errors.Wrapf(err, "failed to apply manifest %s", manifestPath)) + log.Printf("%s", fmt.Errorf("failed to apply manifest %s: %w", manifestPath, err)) } }() @@ -151,7 +150,7 @@ func waitKubeStateMetricsReadiness(env map[string]string, stdOut, stdErr io.Writ break } if readyAttempts > checkKubeStateMetricsReadyAttempts { - return errors.Wrapf(err, "Timeout waiting for kube-state-metrics") + return fmt.Errorf("timeout waiting for kube-state-metrics: %w", err) } time.Sleep(6 * time.Second) readyAttempts++ @@ -164,12 +163,12 @@ func waitKubeStateMetricsReadiness(env map[string]string, stdOut, stdErr io.Writ func kubernetesClusterName() string { commit, err := mage.CommitHash() if err != nil { - panic(errors.Wrap(err, "failed to construct kind cluster name")) + panic(fmt.Errorf("failed to construct kind cluster name: %w", err)) } version, err := mage.BeatQualifiedVersion() if err != nil { - panic(errors.Wrap(err, "failed to construct kind cluster name")) + panic(fmt.Errorf("failed to construct kind cluster name: %w", err)) } version = strings.NewReplacer(".", "-").Replace(version) @@ -189,7 +188,7 @@ func kubernetesClusterName() string { // Note that underscores, in particular, are not permitted. matched, err := regexp.MatchString(subDomainPattern, clusterName) if err != nil { - panic(errors.Wrap(err, "error while validating kind cluster name")) + panic(fmt.Errorf("error while validating kind cluster name: %w", err)) } if !matched { panic("constructed invalid kind cluster name") diff --git a/dev-tools/mage/pkgdeps.go b/dev-tools/mage/pkgdeps.go index ed41bf6c09a..56a9ce06c40 100644 --- a/dev-tools/mage/pkgdeps.go +++ b/dev-tools/mage/pkgdeps.go @@ -8,7 +8,6 @@ import ( "fmt" "github.com/magefile/mage/sh" - "github.com/pkg/errors" ) // PackageInstaller contains package dependency @@ -121,7 +120,7 @@ func installDependencies(arch string, pkgs ...string) error { if arch != "" { err := sh.Run("dpkg", "--add-architecture", arch) if err != nil { - return errors.Wrap(err, "error while adding architecture") + return fmt.Errorf("error while adding architecture: %w", err) } } diff --git a/dev-tools/mage/platforms.go b/dev-tools/mage/platforms.go index aa930989294..481b98e4208 100644 --- a/dev-tools/mage/platforms.go +++ b/dev-tools/mage/platforms.go @@ -5,10 +5,9 @@ package mage import ( + "fmt" "sort" "strings" - - "github.com/pkg/errors" ) // BuildPlatforms is a list of GOOS/GOARCH pairs supported by Go. @@ -312,7 +311,7 @@ func newPlatformExpression(expr string) (*platformExpression, error) { } if !valid { - return nil, errors.Errorf("invalid platform in expression: %v", name) + return nil, fmt.Errorf("invalid platform in expression: %v", name) } } @@ -408,7 +407,7 @@ func (list BuildPlatformList) Filter(expr string) BuildPlatformList { return list } if len(pe.Add) > 0 { - panic(errors.Errorf("adds (%v) cannot be used in filter expressions", + panic(fmt.Errorf("adds (%v) cannot be used in filter expressions", strings.Join(pe.Add, ", "))) } @@ -445,7 +444,7 @@ func (list BuildPlatformList) Filter(expr string) BuildPlatformList { // Merge creates a new list with the two list merged. func (list BuildPlatformList) Merge(with BuildPlatformList) BuildPlatformList { out := make(BuildPlatformList, 0, len(list)+len(with)) - out = append(list, with...) + out = append(out, list...) out = append(out, with...) return out.deduplicate() } diff --git a/go.mod b/go.mod index e0f4e5fe536..b9e93bfd3eb 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,6 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.107.0 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinreceiver v0.107.0 github.com/otiai10/copy v1.14.0 - github.com/pkg/errors v0.9.1 github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 github.com/rs/zerolog v1.27.0 github.com/sajari/regression v1.0.1 @@ -289,6 +288,7 @@ require ( github.com/openzipkin/zipkin-go v0.4.3 // indirect github.com/ovh/go-ovh v1.5.1 // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect github.com/prometheus-community/windows_exporter v0.25.1 // indirect diff --git a/internal/pkg/agent/errors/error_test.go b/internal/pkg/agent/errors/error_test.go index 69b89b968f1..4945b43b4c4 100644 --- a/internal/pkg/agent/errors/error_test.go +++ b/internal/pkg/agent/errors/error_test.go @@ -8,12 +8,11 @@ package errors import ( + "errors" "fmt" "io" "testing" - //nolint:gomodguard // Postpone the change here until we refactor error handling. - "github.com/pkg/errors" "github.com/stretchr/testify/assert" ) @@ -26,11 +25,11 @@ func TestErrorsIs(t *testing.T) { } simpleErr := io.ErrNoProgress - simpleWrap := errors.Wrap(simpleErr, "wrapping %w") + simpleWrap := fmt.Errorf("wrapping %w", simpleErr) agentErr := New() nestedSimple := New(simpleErr) nestedWrap := New(simpleWrap) - agentInErr := errors.Wrap(nestedWrap, "wrapping %w") + agentInErr := fmt.Errorf("wrapping %w", nestedWrap) tt := []testCase{ {"simple wrap", simpleWrap, simpleErr, true}, @@ -65,7 +64,7 @@ func TestErrorsIs(t *testing.T) { func TestErrorsWrap(t *testing.T) { ce := New("custom error", TypePath, M("k", "v")) - ew := errors.Wrap(ce, "wrapper") + ew := fmt.Errorf("wrapper: %w", ce) outer := New(ew) outerCustom, ok := outer.(Error) diff --git a/internal/pkg/crypto/io.go b/internal/pkg/crypto/io.go index 2012bdf1b5c..23bdfcbab02 100644 --- a/internal/pkg/crypto/io.go +++ b/internal/pkg/crypto/io.go @@ -11,10 +11,10 @@ import ( "crypto/rand" "crypto/sha512" "encoding/binary" + "errors" "fmt" "io" - "github.com/pkg/errors" "golang.org/x/crypto/pbkdf2" ) @@ -34,11 +34,11 @@ type Option struct { // Validate the options for encoding and decoding values. func (o *Option) Validate() error { if o.IVLength == 0 { - return errors.New("IV length must be superior to 0") + return errors.New("IVLength must be superior to 0") } if o.SaltLength == 0 { - return errors.New("Salt length must be superior to 0") + return errors.New("SaltLength must be superior to 0") } if o.IterationsCount == 0 { @@ -99,7 +99,7 @@ func NewWriter(writer io.Writer, password []byte, option *Option) (*Writer, erro salt, err := g(option.SaltLength) if err != nil { - return nil, errors.Wrap(err, "fail to generate random password salt") + return nil, fmt.Errorf("fail to generate random password salt: %w", err) } return &Writer{ @@ -137,13 +137,13 @@ func (w *Writer) Write(b []byte) (int, error) { // Select AES-256: because len(passwordBytes) == 32 bytes. block, err := aes.NewCipher(passwordBytes) if err != nil { - w.err = errors.Wrap(err, "could not create the cipher to encrypt") + w.err = fmt.Errorf("could not create the cipher to encrypt: %w", err) return 0, w.err } aesgcm, err := cipher.NewGCM(block) if err != nil { - w.err = errors.Wrap(err, "could not create the GCM to encrypt") + w.err = fmt.Errorf("could not create the GCM to encrypt: %w", err) return 0, w.err } @@ -157,7 +157,7 @@ func (w *Writer) Write(b []byte) (int, error) { n, err := w.writer.Write(header.Bytes()) if err != nil { - w.err = errors.Wrap(err, "fail to write encoding information header") + w.err = fmt.Errorf("fail to write encoding information header: %w", err) return 0, w.err } @@ -166,14 +166,14 @@ func (w *Writer) Write(b []byte) (int, error) { } if err := w.writeBlock(b); err != nil { - return 0, errors.Wrap(err, "fail to write block") + return 0, fmt.Errorf("fail to write block: %w", err) } return len(b), err } if err := w.writeBlock(b); err != nil { - return 0, errors.Wrap(err, "fail to write block") + return 0, fmt.Errorf("fail to write block: %w", err) } return len(b), nil @@ -184,23 +184,23 @@ func (w *Writer) writeBlock(b []byte) error { // on disk in the file as part of the header iv, err := w.generator(w.option.IVLength) if err != nil { - w.err = errors.Wrap(err, "fail to generate random IV") + w.err = fmt.Errorf("fail to generate random IV: %w", err) return w.err } - // nolint: errcheck // Ignore the error at this point. + //nolint:errcheck // Ignore the error at this point. w.writer.Write(iv) encodedBytes := w.gcm.Seal(nil, iv, b, nil) l := make([]byte, 4) binary.LittleEndian.PutUint32(l, uint32(len(encodedBytes))) - // nolint: errcheck // Ignore the error at this point. + //nolint:errcheck // Ignore the error at this point. w.writer.Write(l) _, err = w.writer.Write(encodedBytes) if err != nil { - return errors.Wrap(err, "fail to encode data") + return fmt.Errorf("fail to encode data: %w", err) } return nil @@ -253,7 +253,7 @@ func (r *Reader) Read(b []byte) (int, error) { buf := make([]byte, vLen+r.option.SaltLength) n, err := io.ReadAtLeast(r.reader, buf, len(buf)) if err != nil { - r.err = errors.Wrap(err, "fail to read encoding header") + r.err = fmt.Errorf("fail to read encoding header: %w", err) return n, err } @@ -274,13 +274,13 @@ func (r *Reader) Read(b []byte) (int, error) { block, err := aes.NewCipher(passwordBytes) if err != nil { - r.err = errors.Wrap(err, "could not create the cipher to decrypt the data") + r.err = fmt.Errorf("could not create the cipher to decrypt the data: %w", err) return 0, r.err } aesgcm, err := cipher.NewGCM(block) if err != nil { - r.err = errors.Wrap(err, "could not create the GCM to decrypt the data") + r.err = fmt.Errorf("could not create the GCM to decrypt the data: %w", err) return 0, r.err } r.gcm = aesgcm @@ -328,12 +328,12 @@ func (r *Reader) consumeBlock() error { encodedBytes := make([]byte, l) _, err = io.ReadAtLeast(r.reader, encodedBytes, l) if err != nil { - r.err = errors.Wrapf(err, "fail read the block of %d bytes", l) + r.err = fmt.Errorf("fail read the block of %d bytes: %w", l, err) } decodedBytes, err := r.gcm.Open(nil, iv, encodedBytes, nil) if err != nil { - return errors.Wrap(err, "fail to decode bytes") + return fmt.Errorf("fail to decode bytes: %w", err) } r.buf = append(r.buf[:], decodedBytes...) diff --git a/internal/pkg/remote/round_trippers.go b/internal/pkg/remote/round_trippers.go index 76c3fec139e..899d2693ead 100644 --- a/internal/pkg/remote/round_trippers.go +++ b/internal/pkg/remote/round_trippers.go @@ -12,8 +12,6 @@ import ( "net/http" "strings" "time" - - "github.com/pkg/errors" ) // UserAgentRoundTripper adds a User-Agent string on every request. @@ -69,7 +67,7 @@ func (r *DebugRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) if req.Body != nil { dataReq, err := io.ReadAll(req.Body) if err != nil { - return nil, errors.Wrap(err, "fail to read the body of the request") + return nil, fmt.Errorf("fail to read the body of the request: %w", err) } req.Body.Close() @@ -103,7 +101,7 @@ func (r *DebugRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) // Hijack the body and output it in the log, this is only for debugging and development. data, err := io.ReadAll(resp.Body) if err != nil { - return resp, errors.Wrap(err, "fail to read the body of the response") + return resp, fmt.Errorf("fail to read the body of the response: %w", err) } resp.Body.Close()