Skip to content

Commit

Permalink
progessui: return warnings from printer
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Dec 1, 2021
1 parent d100814 commit 0dd260b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/build-using-dockerfile/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ func action(clicontext *cli.Context) error {
c = cn
}
// not using shared context to not disrupt display but let is finish reporting errors
return progressui.DisplaySolveStatus(context.TODO(), "", c, os.Stdout, ch)
_, err = progressui.DisplaySolveStatus(context.TODO(), "", c, os.Stdout, ch)
return err
})
eg.Go(func() error {
if err := loadDockerTar(pipeR); err != nil {
Expand Down
16 changes: 12 additions & 4 deletions util/progress/progressui/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"golang.org/x/time/rate"
)

func DisplaySolveStatus(ctx context.Context, phase string, c console.Console, w io.Writer, ch chan *client.SolveStatus) error {
func DisplaySolveStatus(ctx context.Context, phase string, c console.Console, w io.Writer, ch chan *client.SolveStatus) ([]client.VertexWarning, error) {
modeConsole := c != nil

disp := &display{c: c, phase: phase}
Expand Down Expand Up @@ -57,7 +57,7 @@ func DisplaySolveStatus(ctx context.Context, phase string, c console.Console, w
for {
select {
case <-ctx.Done():
return ctx.Err()
return nil, ctx.Err()
case <-ticker.C:
case ss, ok := <-ch:
if ok {
Expand All @@ -72,7 +72,7 @@ func DisplaySolveStatus(ctx context.Context, phase string, c console.Console, w
if done {
disp.print(t.displayInfo(), width, height, true)
t.printErrorLogs(c)
return nil
return t.warnings(), nil
} else if displayLimiter.Allow() {
ticker.Stop()
ticker = time.NewTicker(tickerTimeout)
Expand All @@ -83,7 +83,7 @@ func DisplaySolveStatus(ctx context.Context, phase string, c console.Console, w
printer.print(t)
if done {
t.printErrorLogs(w)
return nil
return t.warnings(), nil
}
ticker.Stop()
ticker = time.NewTicker(tickerTimeout)
Expand Down Expand Up @@ -172,6 +172,14 @@ func newTrace(w io.Writer, modeConsole bool) *trace {
}
}

func (t *trace) warnings() []client.VertexWarning {
var out []client.VertexWarning
for _, v := range t.vertexes {
out = append(out, v.warnings...)
}
return out
}

func (t *trace) triggerVertexEvent(v *client.Vertex) {
if v.Started == nil {
return
Expand Down
2 changes: 1 addition & 1 deletion util/progress/progresswriter/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func NewPrinter(ctx context.Context, out console.File, mode string) (Writer, err

go func() {
// not using shared context to not disrupt display but let is finish reporting errors
pw.err = progressui.DisplaySolveStatus(ctx, "", c, out, statusCh)
_, pw.err = progressui.DisplaySolveStatus(ctx, "", c, out, statusCh)
close(doneCh)
}()
return pw, nil
Expand Down

0 comments on commit 0dd260b

Please sign in to comment.