File: build.go

package info (click to toggle)
docker-buildx 0.19.3%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,852 kB
  • sloc: sh: 318; makefile: 73
file content (48 lines) | stat: -rw-r--r-- 891 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package errdefs

import (
	"io"

	"github.com/containerd/typeurl/v2"
	"github.com/docker/buildx/util/desktop"
	"github.com/moby/buildkit/util/grpcerrors"
)

func init() {
	typeurl.Register((*Build)(nil), "github.com/docker/buildx", "errdefs.Build+json")
}

type BuildError struct {
	*Build
	error
}

func (e *BuildError) Unwrap() error {
	return e.error
}

func (e *BuildError) ToProto() grpcerrors.TypedErrorProto {
	return e.Build
}

func (e *BuildError) PrintBuildDetails(w io.Writer) error {
	if e.Ref == "" {
		return nil
	}
	ebr := &desktop.ErrorWithBuildRef{
		Ref: e.Ref,
		Err: e.error,
	}
	return ebr.Print(w)
}

func WrapBuild(err error, sessionID string, ref string) error {
	if err == nil {
		return nil
	}
	return &BuildError{Build: &Build{SessionID: sessionID, Ref: ref}, error: err}
}

func (b *Build) WrapError(err error) error {
	return &BuildError{error: err, Build: b}
}