MCPcopy
hub / github.com/vmware-tanzu/sonobuoy / RunLoggingOutputOnFail

Function RunLoggingOutputOnFail

pkg/image/exec/exec.go:85–108  ·  view source on GitHub ↗

RunLoggingOutputOnFail runs the cmd, logging error output if Run returns an error

(cmd Cmd, retries int)

Source from the content-addressed store, hash-verified

83
84// RunLoggingOutputOnFail runs the cmd, logging error output if Run returns an error
85func RunLoggingOutputOnFail(cmd Cmd, retries int) error {
86 var buff bytes.Buffer
87 cmd.SetStdout(&buff)
88 cmd.SetStderr(&buff)
89 err := cmd.Run()
90 if err != nil {
91 // retry pulling up to retries times if necessary
92 for i := 0; i < retries; i++ {
93 time.Sleep(time.Second * time.Duration(i+1))
94 err = cmd.Run()
95 if err == nil {
96 return nil
97 }
98 }
99
100 // All retries failed or none were requested
101 log.Errorf("failed with following error after %d retries:", retries)
102 scanner := bufio.NewScanner(&buff)
103 for scanner.Scan() {
104 log.Error(scanner.Text())
105 }
106 }
107 return err
108}

Callers 5

PullMethod · 0.92
PushMethod · 0.92
TagMethod · 0.92
RmiMethod · 0.92
SaveMethod · 0.92

Calls 4

SetStdoutMethod · 0.65
SetStderrMethod · 0.65
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected