diff --git a/go.mod b/go.mod index ef25472..3ebe7bb 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module git.jakstys.lt/motiejus/undocker -go 1.16 +go 1.20 diff --git a/main.go b/main.go index 65d3ef1..b48ed1b 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( + "errors" "fmt" "io" "os" @@ -59,10 +60,7 @@ func (c *command) execute(infile string, outfile string) (_err error) { return err } defer func() { - err := rd.Close() - if _err == nil { - _err = err - } + _err = errors.Join(_err, rd.Close()) }() var out io.Writer @@ -74,11 +72,10 @@ func (c *command) execute(infile string, outfile string) (_err error) { return fmt.Errorf("create: %w", err) } defer func() { - err := outf.Close() if _err != nil { - os.Remove(outfile) + _err = errors.Join(_err, os.Remove(outfile)) } else { - _err = err + _err = errors.Join(_err, outf.Close()) } }() out = outf diff --git a/rootfs/rootfs.go b/rootfs/rootfs.go index 5de314b..015ba32 100644 --- a/rootfs/rootfs.go +++ b/rootfs/rootfs.go @@ -144,11 +144,7 @@ func Flatten(rd io.ReadSeeker, w io.Writer) (_err error) { tw := tar.NewWriter(w) defer func() { - // Avoiding use of multierr: if error is present, return - // that. Otherwise return whatever `Close` returns. - if err := tw.Close(); err != nil && _err == nil { - _err = err - } + _err = errors.Join(_err, tw.Close()) }() // iterate through all layers, all files, and write files. for i, no := range layers {