2022-01-19 19:48:57 +00:00
|
|
|
package moby_buildkit_v1_frontend //nolint:revive
|
2020-08-05 01:11:32 +00:00
|
|
|
|
2021-07-28 21:49:33 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/containerd/typeurl"
|
|
|
|
"github.com/moby/buildkit/util/grpcerrors"
|
|
|
|
)
|
2020-08-05 01:11:32 +00:00
|
|
|
|
2020-11-17 23:11:09 +00:00
|
|
|
const (
|
2020-12-06 22:59:28 +00:00
|
|
|
// UnknownExitStatus might be returned in (*ExitError).ExitCode via
|
|
|
|
// ContainerProcess.Wait. This can happen if the process never starts
|
2020-11-17 23:11:09 +00:00
|
|
|
// 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
|
2020-12-06 22:59:28 +00:00
|
|
|
UnknownExitStatus = 255
|
2020-11-17 23:11:09 +00:00
|
|
|
)
|
|
|
|
|
2021-07-28 21:49:33 +00:00
|
|
|
func init() {
|
|
|
|
typeurl.Register((*ExitMessage)(nil), "github.com/moby/buildkit", "gatewayapi.ExitMessage+json")
|
|
|
|
}
|
|
|
|
|
2020-08-05 01:11:32 +00:00
|
|
|
// ExitError will be returned when the container process exits with a non-zero
|
|
|
|
// exit code.
|
|
|
|
type ExitError struct {
|
|
|
|
ExitCode uint32
|
|
|
|
Err error
|
|
|
|
}
|
|
|
|
|
2021-07-28 21:49:33 +00:00
|
|
|
func (err *ExitError) ToProto() grpcerrors.TypedErrorProto {
|
|
|
|
return &ExitMessage{
|
|
|
|
Code: err.ExitCode,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-05 01:11:32 +00:00
|
|
|
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
|
|
|
|
}
|
2021-07-28 21:49:33 +00:00
|
|
|
|
|
|
|
func (e *ExitMessage) WrapError(err error) error {
|
|
|
|
return &ExitError{
|
|
|
|
Err: err,
|
|
|
|
ExitCode: e.Code,
|
|
|
|
}
|
|
|
|
}
|