@@ -85,6 +85,7 @@ func (runner *Runner) RunPiped(ctx context.Context, inv Invocation, stdout, stde
8585
8686// RunRaw runs the invocation, serializing requests only if they fight over
8787// go.mod changes.
88+ // Postcondition: both error results have same nilness.
8889func (runner * Runner ) RunRaw (ctx context.Context , inv Invocation ) (* bytes.Buffer , * bytes.Buffer , error , error ) {
8990 ctx , done := event .Start (ctx , "gocommand.Runner.RunRaw" , invLabels (inv )... )
9091 defer done ()
@@ -95,23 +96,24 @@ func (runner *Runner) RunRaw(ctx context.Context, inv Invocation) (*bytes.Buffer
9596 stdout , stderr , friendlyErr , err := runner .runConcurrent (ctx , inv )
9697
9798 // If we encounter a load concurrency error, we need to retry serially.
98- if friendlyErr == nil || ! modConcurrencyError .MatchString (friendlyErr .Error ()) {
99- return stdout , stderr , friendlyErr , err
99+ if friendlyErr != nil && modConcurrencyError .MatchString (friendlyErr .Error ()) {
100+ event .Error (ctx , "Load concurrency error, will retry serially" , err )
101+
102+ // Run serially by calling runPiped.
103+ stdout .Reset ()
104+ stderr .Reset ()
105+ friendlyErr , err = runner .runPiped (ctx , inv , stdout , stderr )
100106 }
101- event .Error (ctx , "Load concurrency error, will retry serially" , err )
102107
103- // Run serially by calling runPiped.
104- stdout .Reset ()
105- stderr .Reset ()
106- friendlyErr , err = runner .runPiped (ctx , inv , stdout , stderr )
107108 return stdout , stderr , friendlyErr , err
108109}
109110
111+ // Postcondition: both error results have same nilness.
110112func (runner * Runner ) runConcurrent (ctx context.Context , inv Invocation ) (* bytes.Buffer , * bytes.Buffer , error , error ) {
111113 // Wait for 1 worker to become available.
112114 select {
113115 case <- ctx .Done ():
114- return nil , nil , nil , ctx .Err ()
116+ return nil , nil , ctx . Err () , ctx .Err ()
115117 case runner .inFlight <- struct {}{}:
116118 defer func () { <- runner .inFlight }()
117119 }
@@ -121,6 +123,7 @@ func (runner *Runner) runConcurrent(ctx context.Context, inv Invocation) (*bytes
121123 return stdout , stderr , friendlyErr , err
122124}
123125
126+ // Postcondition: both error results have same nilness.
124127func (runner * Runner ) runPiped (ctx context.Context , inv Invocation , stdout , stderr io.Writer ) (error , error ) {
125128 // Make sure the runner is always initialized.
126129 runner .initialize ()
@@ -129,7 +132,7 @@ func (runner *Runner) runPiped(ctx context.Context, inv Invocation, stdout, stde
129132 // runPiped commands.
130133 select {
131134 case <- ctx .Done ():
132- return nil , ctx .Err ()
135+ return ctx . Err () , ctx .Err ()
133136 case runner .serialized <- struct {}{}:
134137 defer func () { <- runner .serialized }()
135138 }
@@ -139,7 +142,7 @@ func (runner *Runner) runPiped(ctx context.Context, inv Invocation, stdout, stde
139142 for i := 0 ; i < maxInFlight ; i ++ {
140143 select {
141144 case <- ctx .Done ():
142- return nil , ctx .Err ()
145+ return ctx . Err () , ctx .Err ()
143146 case runner .inFlight <- struct {}{}:
144147 // Make sure we always "return" any workers we took.
145148 defer func () { <- runner .inFlight }()
@@ -172,6 +175,7 @@ type Invocation struct {
172175 Logf func (format string , args ... interface {})
173176}
174177
178+ // Postcondition: both error results have same nilness.
175179func (i * Invocation ) runWithFriendlyError (ctx context.Context , stdout , stderr io.Writer ) (friendlyError error , rawError error ) {
176180 rawError = i .run (ctx , stdout , stderr )
177181 if rawError != nil {
0 commit comments