error reporting

This commit is contained in:
Motiejus Jakštys 2021-05-24 00:11:58 +03:00
parent ef777d9e86
commit f9eea46417
2 changed files with 10 additions and 3 deletions

1
BUILD
View File

@ -8,6 +8,7 @@ go_library(
deps = [ deps = [
"//src/undocker/rootfs:go_default_library", "//src/undocker/rootfs:go_default_library",
"@com_github_jessevdk_go_flags//:go_default_library", "@com_github_jessevdk_go_flags//:go_default_library",
"@org_uber_go_multierr//:go_default_library",
], ],
) )

12
main.go
View File

@ -6,6 +6,7 @@ import (
goflags "github.com/jessevdk/go-flags" goflags "github.com/jessevdk/go-flags"
"github.com/motiejus/code/undocker/rootfs" "github.com/motiejus/code/undocker/rootfs"
"go.uber.org/multierr"
) )
type ( type (
@ -40,7 +41,7 @@ type cmdRootFS struct {
} `positional-args:"yes" required:"yes"` } `positional-args:"yes" required:"yes"`
} }
func (r *cmdRootFS) Execute(args []string) error { func (r *cmdRootFS) Execute(args []string) (err error) {
if len(args) != 0 { if len(args) != 0 {
return errors.New("too many args") return errors.New("too many args")
} }
@ -49,12 +50,17 @@ func (r *cmdRootFS) Execute(args []string) error {
if err != nil { if err != nil {
return err return err
} }
defer in.Close() defer func() {
err = multierr.Append(err, in.Close())
}()
out, err := os.Create(string(r.PositionalArgs.Outfile)) out, err := os.Create(string(r.PositionalArgs.Outfile))
if err != nil { if err != nil {
return err return err
} }
defer out.Close() defer func() {
err = multierr.Append(err, out.Close())
}()
return rootfs.RootFS(in, out) return rootfs.RootFS(in, out)
} }