github.com/Benchkram/bob@v0.0.0-20220321080157-7c8f3876e225/pkg/cmdutil/error.go (about) 1 package cmdutil 2 3 // copied from https://github.com/cli/cli/blob/trunk/internal/run/run.go 4 5 import ( 6 "bytes" 7 "fmt" 8 "strings" 9 ) 10 11 type CmdError struct { 12 Stderr *bytes.Buffer 13 Args []string 14 Err error 15 } 16 17 func (e CmdError) Error() string { 18 msg := e.Stderr.String() 19 if msg != "" && !strings.HasSuffix(msg, "\n") { 20 msg += "\n" 21 } 22 return fmt.Sprintf("%s%s: %s", msg, e.Args[0], e.Err) 23 }