diff --git a/build/build.go b/build/build.go index d6987db3..10b3aaef 100644 --- a/build/build.go +++ b/build/build.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + ioutils "github.com/jfrog/gofrog/io" "os" "path/filepath" "sort" @@ -225,12 +226,7 @@ func (b *Build) SaveBuildInfo(buildInfo *entities.BuildInfo) (err error) { if err != nil { return } - defer func() { - e := tempFile.Close() - if err == nil { - err = e - } - }() + defer ioutils.Close(tempFile, &err) _, err = tempFile.Write(content.Bytes()) return } @@ -257,12 +253,7 @@ func (b *Build) SavePartialBuildInfo(partial *entities.Partial) (err error) { if err != nil { return } - defer func() { - e := tempFile.Close() - if err == nil { - err = e - } - }() + defer ioutils.Close(tempFile, &err) _, err = tempFile.Write(content.Bytes()) return } diff --git a/build/maven.go b/build/maven.go index 091c28f0..36bc29ab 100644 --- a/build/maven.go +++ b/build/maven.go @@ -173,10 +173,7 @@ func (mm *MavenModule) CalcDependencies() (err error) { defer func() { fileExist, e := utils.IsFileExists(mvnRunConfig.buildInfoProperties, false) if fileExist && e == nil { - e = os.Remove(mvnRunConfig.buildInfoProperties) - } - if err == nil { - err = e + err = errors.Join(err, os.Remove(mvnRunConfig.buildInfoProperties)) } }() mvnRunConfig.SetOutputWriter(mm.outputWriter) diff --git a/go.mod b/go.mod index 5f2f414c..909d30c7 100644 --- a/go.mod +++ b/go.mod @@ -8,10 +8,10 @@ require ( github.com/buger/jsonparser v1.1.1 github.com/jfrog/gofrog v1.6.3 github.com/minio/sha256-simd v1.0.1 - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/urfave/cli/v2 v2.27.1 github.com/xeipuuv/gojsonschema v1.2.0 - golang.org/x/exp v0.0.0-20240213143201-ec583247a57a + golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 ) require ( diff --git a/go.sum b/go.sum index 2817b1be..8550baf8 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/terminalstatic/go-xsd-validate v0.1.5 h1:RqpJnf6HGE2CB/lZB1A8BYguk8uRtcvYAPLCF15qguo= github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= @@ -35,8 +35,8 @@ github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17 github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= -golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE= -golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= +golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 h1:6R2FC06FonbXQ8pK11/PDFY6N6LWlf9KlzibaCapmqc= +golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e h1:CsOuNlbOuf0mzxJIefr6Q4uAUetRUwZE4qt7VfzP+xo= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= diff --git a/utils/checksum.go b/utils/checksum.go index 8508404b..93d8fab8 100644 --- a/utils/checksum.go +++ b/utils/checksum.go @@ -2,7 +2,7 @@ package utils import ( "bufio" - "errors" + ioutils "github.com/jfrog/gofrog/io" //#nosec G501 -- md5 is supported by Artifactory. "crypto/md5" @@ -37,9 +37,7 @@ func GetFileChecksums(filePath string, checksumType ...Algorithm) (checksums map if err != nil { return } - defer func() { - err = errors.Join(err, file.Close()) - }() + defer ioutils.Close(file, &err) return CalcChecksums(file, checksumType...) } diff --git a/utils/pythonutils/piputils.go b/utils/pythonutils/piputils.go index 5953c64b..b420aa19 100644 --- a/utils/pythonutils/piputils.go +++ b/utils/pythonutils/piputils.go @@ -115,10 +115,7 @@ func getEgginfoPkginfoContent(setuppyFilePath string) (output []byte, err error) return nil, err } defer func() { - e := utils.RemoveTempDir(eggBase) - if err == nil { - err = e - } + err = errors.Join(err, utils.RemoveTempDir(eggBase)) }() // Run python 'egg_info --egg-base ' command.