@@ -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 {
@@ -180,7 +181,14 @@ func (p *ProgressDigester) Handle(ev events.Eventer) error {
180181 if p .buildBar == nil {
181182 return errs .New ("BuildFailure called before buildbar was initialized" )
182183 }
184+ logging .Debug ("BuildFailure called, aborting bars" )
183185 p .buildBar .Abort (false ) // mpb has been known to stick around after it was told not to
186+ if p .downloadBar != nil {
187+ p .downloadBar .Abort (false )
188+ }
189+ if p .installBar != nil {
190+ p .installBar .Abort (false )
191+ }
184192
185193 case events.ArtifactBuildStarted :
186194 if p .buildBar == nil {
@@ -304,27 +312,31 @@ func (p *ProgressDigester) Close() error {
304312 case <- time .After (time .Second ):
305313 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.
306314
307- bars := map [string ]* bar {
308- "build bar" : p .buildBar ,
309- "download bar" : p .downloadBar ,
310- "install bar" : p .installBar ,
311- }
312-
313- pending := 0
314- debugMsg := []string {}
315- for name , bar := range bars {
316- debugMsg = append (debugMsg , fmt .Sprintf ("%s is at %v" , name , func () string {
317- if bar == nil {
318- return "nil"
319- }
320- if ! bar .Completed () {
321- pending ++
322- }
323- return fmt .Sprintf ("%d out of %d" , bar .Current (), bar .total )
324- }()))
325- }
326-
327- logging .Debug (`
315+ // Only if the installation was successful do we want to verify that our progress indication was successful.
316+ // There's no point in doing this if it failed as due to the multithreaded nature the failure can bubble up
317+ // in different ways that are difficult to predict and thus verify.
318+ if p .success {
319+ bars := map [string ]* bar {
320+ "build bar" : p .buildBar ,
321+ "download bar" : p .downloadBar ,
322+ "install bar" : p .installBar ,
323+ }
324+
325+ pending := 0
326+ debugMsg := []string {}
327+ for name , bar := range bars {
328+ debugMsg = append (debugMsg , fmt .Sprintf ("%s is at %v" , name , func () string {
329+ if bar == nil {
330+ return "nil"
331+ }
332+ if ! bar .Completed () {
333+ pending ++
334+ }
335+ return fmt .Sprintf ("%d out of %d" , bar .Current (), bar .total )
336+ }()))
337+ }
338+
339+ logging .Debug (`
328340Timed out waiting for progress bars to close.
329341Progress bars status:
330342%s
@@ -334,15 +346,16 @@ Still expecting:
334346 - Installs: %v
335347Event log:
336348%s` ,
337- strings .Join (debugMsg , "\n " ),
338- p .buildsExpected , p .downloadsExpected , p .installsExpected ,
339- strings .Join (p .dbgEventLog , " > " ),
340- )
341-
342- if pending > 0 {
343- // We only error out if we determine the issue is down to one of our bars not completing.
344- // Otherwise this is an issue with the mpb package which is currently a known limitation, end goal is to get rid of mpb.
345- return locale .NewError ("err_rtprogress_outofsync" , "" , constants .BugTrackerURL , logging .FilePath ())
349+ strings .Join (debugMsg , "\n " ),
350+ p .buildsExpected , p .downloadsExpected , p .installsExpected ,
351+ strings .Join (p .dbgEventLog , " > " ),
352+ )
353+
354+ if pending > 0 {
355+ // We only error out if we determine the issue is down to one of our bars not completing.
356+ // Otherwise this is an issue with the mpb package which is currently a known limitation, end goal is to get rid of mpb.
357+ return locale .NewError ("err_rtprogress_outofsync" , "" , constants .BugTrackerURL , logging .FilePath ())
358+ }
346359 }
347360 }
348361
0 commit comments