From be47ebb0eb17e47c9f1f84156e17aa6970d47435 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 17 May 2018 17:18:24 +0200 Subject: pkg/kernel: allow to split full make output Currently kernel build failures are insanely verbose (contain full kernel build output) and there is no way to separate short descriptions from full output. Make it possible. Also try to extract failure root cause froom build log. Use this in pkg/bisect to not pollute log on build failures. Update #501 --- pkg/osutil/osutil.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'pkg/osutil') diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index a1d65e835..e41ad7ec1 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -47,8 +47,10 @@ func Run(timeout time.Duration, cmd *exec.Cmd) ([]byte, error) { }() defer close(done) if err := cmd.Wait(); err != nil { - return nil, fmt.Errorf("failed to run %v %+v: %v\n%v", - cmd.Path, cmd.Args, err, output.String()) + return nil, &VerboseError{ + Title: fmt.Sprintf("failed to run %v %+v: %v", cmd.Path, cmd.Args, err), + Output: output.Bytes(), + } } return output.Bytes(), nil } @@ -60,6 +62,25 @@ func Command(bin string, args ...string) *exec.Cmd { return cmd } +type VerboseError struct { + Title string + Output []byte +} + +func (err *VerboseError) Error() string { + return fmt.Sprintf("%v\n%s", err.Title, err.Output) +} + +func PrependContext(ctx string, err error) error { + switch err1 := err.(type) { + case *VerboseError: + err1.Title = fmt.Sprintf("%v: %v", ctx, err1.Title) + return err1 + default: + return fmt.Errorf("%v: %v", ctx, err) + } +} + // IsExist returns true if the file name exists. func IsExist(name string) bool { _, err := os.Stat(name) -- cgit mrf-deployment