From f9eea4641799d0eace3d1cf6ac18d0632e892205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 24 May 2021 00:11:58 +0300 Subject: [PATCH] error reporting --- BUILD | 1 + main.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/BUILD b/BUILD index d2e351c..2453045 100644 --- a/BUILD +++ b/BUILD @@ -8,6 +8,7 @@ go_library( deps = [ "//src/undocker/rootfs:go_default_library", "@com_github_jessevdk_go_flags//:go_default_library", + "@org_uber_go_multierr//:go_default_library", ], ) diff --git a/main.go b/main.go index e4d16d9..1262af6 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( goflags "github.com/jessevdk/go-flags" "github.com/motiejus/code/undocker/rootfs" + "go.uber.org/multierr" ) type ( @@ -40,7 +41,7 @@ type cmdRootFS struct { } `positional-args:"yes" required:"yes"` } -func (r *cmdRootFS) Execute(args []string) error { +func (r *cmdRootFS) Execute(args []string) (err error) { if len(args) != 0 { return errors.New("too many args") } @@ -49,12 +50,17 @@ func (r *cmdRootFS) Execute(args []string) error { if err != nil { return err } - defer in.Close() + defer func() { + err = multierr.Append(err, in.Close()) + }() out, err := os.Create(string(r.PositionalArgs.Outfile)) if err != nil { return err } - defer out.Close() + defer func() { + err = multierr.Append(err, out.Close()) + }() + return rootfs.RootFS(in, out) }