Skip to content

Commit d25bb03

Browse files
committed
history: add error sources to json output for inspect
Signed-off-by: CrazyMax <[email protected]>
1 parent ccca7c7 commit d25bb03

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

commands/history/inspect.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ type errorOutput struct {
116116
Message string `json:"message,omitempty"`
117117
Name string `json:"name,omitempty"`
118118
Logs []string `json:"logs,omitempty"`
119+
Sources []byte `json:"sources,omitempty"`
119120

120121
statusErr error
121122
}
@@ -315,6 +316,12 @@ workers0:
315316
return errors.Wrapf(err, "failed to unmarshal external error %s", rec.ExternalError.Digest)
316317
}
317318
out.Error.statusErr = grpcerrors.FromGRPC(status.ErrorProto(&st))
319+
var errsources bytes.Buffer
320+
for _, s := range errdefs.Sources(out.Error.statusErr) {
321+
s.Print(&errsources)
322+
errsources.WriteString("\n")
323+
}
324+
out.Error.Sources = errsources.Bytes()
318325
var ve *errdefs.VertexError
319326
if errors.As(out.Error.statusErr, &ve) {
320327
dgst, err := digest.Parse(ve.Vertex.Digest)
@@ -566,10 +573,9 @@ workers0:
566573
}
567574

568575
if out.Error != nil {
569-
for _, s := range errdefs.Sources(out.Error.statusErr) {
570-
s.Print(dockerCli.Out())
576+
if out.Error.Sources != nil {
577+
fmt.Fprint(dockerCli.Out(), string(out.Error.Sources))
571578
}
572-
fmt.Fprintln(dockerCli.Out())
573579
if len(out.Error.Logs) > 0 {
574580
fmt.Fprintln(dockerCli.Out(), "Logs:")
575581
fmt.Fprintf(dockerCli.Out(), "> => %s:\n", out.Error.Name)

0 commit comments

Comments
 (0)