Debian Codegraph @

buildkit/frontend/gateway/pb/exit.go

raw
1 package moby_buildkit_v1_frontend //nolint:revive,staticcheck
2
3 import (
4 "fmt"
5
6 "github.com/containerd/typeurl/v2"
7 "github.com/moby/buildkit/util/grpcerrors"
8 )
9
10 const (
11 // UnknownExitStatus might be returned in (*ExitError).ExitCode via
12 // ContainerProcess.Wait. This can happen if the process never starts
13 // or if an error was encountered when obtaining the exit status, it is set to 255.
14 //
15 // This const is defined here to prevent importing github.com/containerd/containerd
16 // and corresponds with https://github.com/containerd/containerd/blob/40b22ef0741028917761d8c5d5d29e0d19038836/task.go#L52-L55
17 UnknownExitStatus = 255
18 )
19
20 func init() {
21 typeurl.Register((*ExitMessage)(nil), "github.com/moby/buildkit", "gatewayapi.ExitMessage+json")
22 }
23
24 // ExitError will be returned when the container process exits with a non-zero
25 // exit code.
26 type ExitError struct {
27 ExitCode uint32
28 Err error
29 }
30
31 func (err *ExitError) ToProto() grpcerrors.TypedErrorProto {
32 return &ExitMessage{
33 Code: err.ExitCode,
34 }
35 }
36
37 func (err *ExitError) Error() string {
38 if err.Err != nil {
39 return err.Err.Error()
40 }
41 return fmt.Sprintf("exit code: %d", err.ExitCode)
42 }
43
44 func (err *ExitError) Unwrap() error {
45 return err.Err
46 }
47
48 func (e *ExitMessage) WrapError(err error) error {
49 return &ExitError{
50 Err: err,
51 ExitCode: e.Code,
52 }
53 }