Skip to content

Commit

Permalink
split warning message into short and detail
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Dec 3, 2021
1 parent 0dd260b commit 71316c6
Show file tree
Hide file tree
Showing 18 changed files with 407 additions and 286 deletions.
276 changes: 165 additions & 111 deletions api/services/control/control.pb.go

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions api/services/control/control.proto
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ message VertexLog {
message VertexWarning {
string vertex = 1 [(gogoproto.customtype) = "github.com/opencontainers/go-digest.Digest", (gogoproto.nullable) = false];
int64 level = 2;
bytes msg = 3;
pb.SourceInfo info = 4;
repeated pb.Range ranges = 5;
bytes short = 3;
bytes detail = 4;
pb.SourceInfo info = 5;
repeated pb.Range ranges = 6;
}

message BytesMessage {
Expand Down
4 changes: 3 additions & 1 deletion client/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func testWarnings(t *testing.T, sb integration.Sandbox) {
Range: []*pb.Range{
{Start: pb.Position{Line: 2}, End: pb.Position{Line: 4}},
},
Detail: []byte("this is detail"),
}))

return r, nil
Expand Down Expand Up @@ -239,7 +240,8 @@ func testWarnings(t *testing.T, sb integration.Sandbox) {

w := warnings[0]

require.Equal(t, "this is warning", string(w.Message))
require.Equal(t, "this is warning", string(w.Short))
require.Equal(t, "this is detail", string(w.Detail))
require.Equal(t, 3, w.Level)
_, ok := vertexes[w.Vertex]
require.True(t, ok)
Expand Down
3 changes: 2 additions & 1 deletion client/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type VertexLog struct {
type VertexWarning struct {
Vertex digest.Digest
Level int
Message []byte
Short []byte
Detail []byte
SourceInfo *pb.SourceInfo
Range []*pb.Range
}
Expand Down
3 changes: 2 additions & 1 deletion client/solve.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG
s.Warnings = append(s.Warnings, &VertexWarning{
Vertex: v.Vertex,
Level: int(v.Level),
Message: v.Msg,
Short: v.Short,
Detail: v.Detail,
SourceInfo: v.Info,
Range: v.Ranges,
})
Expand Down
3 changes: 2 additions & 1 deletion control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ func (c *Controller) Status(req *controlapi.StatusRequest, stream controlapi.Con
sr.Warnings = append(sr.Warnings, &controlapi.VertexWarning{
Vertex: v.Vertex,
Level: int64(v.Level),
Msg: v.Message,
Short: v.Short,
Detail: v.Detail,
Info: v.SourceInfo,
Ranges: v.Range,
})
Expand Down
8 changes: 4 additions & 4 deletions frontend/dockerfile/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,11 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
LLBCaps: &caps,
SourceMap: sourceMap,
Hostname: opts[keyHostname],
Warn: func(msg string, location *parser.Range) {
Warn: func(msg, detail string, location *parser.Range) {
if i != 0 {
return
}
c.Warn(ctx, defVtx, msg, warnOpts(sourceMap, location))
c.Warn(ctx, defVtx, msg, warnOpts(sourceMap, location, detail))
},
})

Expand Down Expand Up @@ -779,8 +779,8 @@ func scopeToSubDir(c *llb.State, fileop bool, dir string) *llb.State {
return &bc
}

func warnOpts(sm *llb.SourceMap, r *parser.Range) client.WarnOpts {
opts := client.WarnOpts{Level: 1}
func warnOpts(sm *llb.SourceMap, r *parser.Range, detail string) client.WarnOpts {
opts := client.WarnOpts{Level: 1, Detail: []byte(detail)}
if r == nil {
return opts
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type ConvertOpt struct {
ContextLocalName string
SourceMap *llb.SourceMap
Hostname string
Warn func(msg string, location *parser.Range)
Warn func(short, detail string, location *parser.Range)
}

func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State, *Image, error) {
Expand All @@ -93,7 +93,7 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
}

for _, w := range dockerfile.Warnings {
opt.Warn(w.Message, w.Location)
opt.Warn(w.Short, w.Detail, w.Location)
}

proxyEnv := proxyEnvFromBuildArgs(opt.BuildArgs)
Expand Down
8 changes: 5 additions & 3 deletions frontend/dockerfile/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ type Result struct {
}

type Warning struct {
Message string
Short string
Detail string
Location *Range
}

Expand All @@ -283,7 +284,7 @@ func (r *Result) PrintWarnings(out io.Writer) {
return
}
for _, w := range r.Warnings {
fmt.Fprintf(out, "[WARNING]: %s\n", w.Message)
fmt.Fprintf(out, "[WARNING]: %s\n", w.Short)
}
if len(r.Warnings) > 0 {
fmt.Fprintf(out, "[WARNING]: Empty continuation lines will become errors in a future release.\n")
Expand Down Expand Up @@ -352,7 +353,8 @@ func Parse(rwc io.Reader) (*Result, error) {

if hasEmptyContinuationLine {
warnings = append(warnings, Warning{
Message: "Empty continuation line found in: " + line,
Short: "Empty continuation line found in: " + line,
Detail: "Empty continuation lines will become errors in a future release. https://github.com/moby/moby/pull/33719",
Location: &Range{Start: Position{Line: currentLine}, End: Position{Line: currentLine}},
})
}
Expand Down
10 changes: 5 additions & 5 deletions frontend/dockerfile/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ RUN indented \
result, err := Parse(dockerfile)
require.NoError(t, err)
warnings := result.Warnings
require.Equal(t, 3, len(warnings))
require.Contains(t, warnings[0], "Empty continuation line found in")
require.Contains(t, warnings[0], "RUN something following more")
require.Contains(t, warnings[1], "RUN another thing")
require.Contains(t, warnings[2], "will become errors in a future release")
require.Equal(t, 2, len(warnings))
require.Contains(t, warnings[0].Short, "Empty continuation line found in")
require.Contains(t, warnings[0].Short, "RUN something following more")
require.Contains(t, warnings[1].Short, "RUN another thing")
require.Contains(t, warnings[0].Detail, "will become errors in a future release")
}

func TestParseReturnsScannerErrors(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions frontend/gateway/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,5 @@ type WarnOpts struct {
Level int
SourceInfo *pb.SourceInfo
Range []*pb.Range
Detail []byte
}
3 changes: 2 additions & 1 deletion frontend/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,11 @@ func (lbf *llbBridgeForwarder) ReleaseContainer(ctx context.Context, in *pb.Rele
}

func (lbf *llbBridgeForwarder) Warn(ctx context.Context, in *pb.WarnRequest) (*pb.WarnResponse, error) {
err := lbf.llbBridge.Warn(ctx, in.Digest, string(in.Message), frontend.WarnOpts{
err := lbf.llbBridge.Warn(ctx, in.Digest, string(in.Short), frontend.WarnOpts{
Level: int(in.Level),
SourceInfo: in.Info,
Range: in.Ranges,
Detail: in.Detail,
})
if err != nil {
return nil, err
Expand Down
11 changes: 6 additions & 5 deletions frontend/gateway/grpcclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,12 @@ func (c *grpcClient) requestForRef(ref client.Reference) (*pb.SolveRequest, erro

func (c *grpcClient) Warn(ctx context.Context, dgst digest.Digest, msg string, opts client.WarnOpts) error {
_, err := c.client.Warn(ctx, &pb.WarnRequest{
Digest: dgst,
Level: int64(opts.Level),
Message: []byte(msg),
Info: opts.SourceInfo,
Ranges: opts.Range,
Digest: dgst,
Level: int64(opts.Level),
Short: []byte(msg),
Info: opts.SourceInfo,
Ranges: opts.Range,
Detail: opts.Detail,
})
return err
}
Expand Down
Loading

0 comments on commit 71316c6

Please sign in to comment.