File: exit.go

package info (click to toggle)
singularity-container 4.1.5%2Bds4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 43,876 kB
  • sloc: asm: 14,840; sh: 3,190; ansic: 1,751; awk: 414; makefile: 413; python: 99
file content (53 lines) | stat: -rw-r--r-- 1,322 bytes parent folder | download | duplicates (3)
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
49
50
51
52
53
package moby_buildkit_v1_frontend //nolint:revive

import (
	"fmt"

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

const (
	// UnknownExitStatus might be returned in (*ExitError).ExitCode via
	// ContainerProcess.Wait.  This can happen if the process never starts
	// or if an error was encountered when obtaining the exit status, it is set to 255.
	//
	// This const is defined here to prevent importing github.com/containerd/containerd
	// and corresponds with https://github.com/containerd/containerd/blob/40b22ef0741028917761d8c5d5d29e0d19038836/task.go#L52-L55
	UnknownExitStatus = 255
)

func init() {
	typeurl.Register((*ExitMessage)(nil), "github.com/moby/buildkit", "gatewayapi.ExitMessage+json")
}

// ExitError will be returned when the container process exits with a non-zero
// exit code.
type ExitError struct {
	ExitCode uint32
	Err      error
}

func (err *ExitError) ToProto() grpcerrors.TypedErrorProto {
	return &ExitMessage{
		Code: err.ExitCode,
	}
}

func (err *ExitError) Error() string {
	if err.Err != nil {
		return err.Err.Error()
	}
	return fmt.Sprintf("exit code: %d", err.ExitCode)
}

func (err *ExitError) Unwrap() error {
	return err.Err
}

func (e *ExitMessage) WrapError(err error) error {
	return &ExitError{
		Err:      err,
		ExitCode: e.Code,
	}
}