aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/osutil
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-05-17 17:18:24 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-05-17 17:18:24 +0200
commitbe47ebb0eb17e47c9f1f84156e17aa6970d47435 (patch)
treec7351c27390bb6eefef00d526dd1c448648c627d /pkg/osutil
parent28cbff8c7d91cd42ee29ebf80c6e9fc4dfbf50e9 (diff)
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
Diffstat (limited to 'pkg/osutil')
-rw-r--r--pkg/osutil/osutil.go25
1 files changed, 23 insertions, 2 deletions
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)