@@ -7,15 +7,16 @@ import (
77 "sync"
88 "time"
99
10+ "github.com/vbauerster/mpb/v7"
11+ "golang.org/x/net/context"
12+
1013 "github.com/ActiveState/cli/internal/constants"
1114 "github.com/ActiveState/cli/internal/errs"
1215 "github.com/ActiveState/cli/internal/locale"
1316 "github.com/ActiveState/cli/internal/logging"
1417 "github.com/ActiveState/cli/internal/output"
1518 "github.com/ActiveState/cli/pkg/platform/runtime/artifact"
1619 "github.com/ActiveState/cli/pkg/platform/runtime/setup/events"
17- "github.com/vbauerster/mpb/v7"
18- "golang.org/x/net/context"
1920)
2021
2122type step struct {
@@ -181,7 +182,14 @@ func (p *ProgressDigester) Handle(ev events.Eventer) error {
181182 if p .buildBar == nil {
182183 return errs .New ("BuildFailure called before buildbar was initialized" )
183184 }
185+ logging .Debug ("BuildFailure called, aborting bars" )
184186 p .buildBar .Abort (false ) // mpb has been known to stick around after it was told not to
187+ if p .downloadBar != nil {
188+ p .downloadBar .Abort (false )
189+ }
190+ if p .installBar != nil {
191+ p .installBar .Abort (false )
192+ }
185193
186194 case events.ArtifactBuildStarted :
187195 if p .buildBar == nil {
@@ -305,27 +313,31 @@ func (p *ProgressDigester) Close() error {
305313 case <- time .After (time .Second ):
306314 p .cancelMpb () // mpb doesn't have a Close, just a Wait. We force it as we don't want to give it the opportunity to block.
307315
308- bars := map [string ]* bar {
309- "build bar" : p .buildBar ,
310- "download bar" : p .downloadBar ,
311- "install bar" : p .installBar ,
312- }
313-
314- pending := 0
315- debugMsg := []string {}
316- for name , bar := range bars {
317- debugMsg = append (debugMsg , fmt .Sprintf ("%s is at %v" , name , func () string {
318- if bar == nil {
319- return "nil"
320- }
321- if ! bar .Completed () {
322- pending ++
323- }
324- return fmt .Sprintf ("%d out of %d" , bar .Current (), bar .total )
325- }()))
326- }
327-
328- logging .Debug (`
316+ // Only if the installation was successful do we want to verify that our progress indication was successful.
317+ // There's no point in doing this if it failed as due to the multithreaded nature the failure can bubble up
318+ // in different ways that are difficult to predict and thus verify.
319+ if p .success {
320+ bars := map [string ]* bar {
321+ "build bar" : p .buildBar ,
322+ "download bar" : p .downloadBar ,
323+ "install bar" : p .installBar ,
324+ }
325+
326+ pending := 0
327+ debugMsg := []string {}
328+ for name , bar := range bars {
329+ debugMsg = append (debugMsg , fmt .Sprintf ("%s is at %v" , name , func () string {
330+ if bar == nil {
331+ return "nil"
332+ }
333+ if ! bar .Completed () {
334+ pending ++
335+ }
336+ return fmt .Sprintf ("%d out of %d" , bar .Current (), bar .total )
337+ }()))
338+ }
339+
340+ logging .Debug (`
329341Timed out waiting for progress bars to close.
330342Progress bars status:
331343%s
@@ -335,15 +347,16 @@ Still expecting:
335347 - Installs: %v
336348Event log:
337349%s` ,
338- strings .Join (debugMsg , "\n " ),
339- p .buildsExpected , p .downloadsExpected , p .installsExpected ,
340- strings .Join (p .dbgEventLog , " > " ),
341- )
342-
343- if pending > 0 {
344- // We only error out if we determine the issue is down to one of our bars not completing.
345- // Otherwise this is an issue with the mpb package which is currently a known limitation, end goal is to get rid of mpb.
346- return locale .NewError ("err_rtprogress_outofsync" , "" , constants .BugTrackerURL , logging .FilePath ())
350+ strings .Join (debugMsg , "\n " ),
351+ p .buildsExpected , p .downloadsExpected , p .installsExpected ,
352+ strings .Join (p .dbgEventLog , " > " ),
353+ )
354+
355+ if pending > 0 {
356+ // We only error out if we determine the issue is down to one of our bars not completing.
357+ // Otherwise this is an issue with the mpb package which is currently a known limitation, end goal is to get rid of mpb.
358+ return locale .NewError ("err_rtprogress_outofsync" , "" , constants .BugTrackerURL , logging .FilePath ())
359+ }
347360 }
348361 }
349362
0 commit comments