mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 17:37:46 +08:00

Removes gogo/protobuf from buildx and updates to a version of moby/buildkit where gogo is removed. This also changes how the proto files are generated. This is because newer versions of protobuf are more strict about name conflicts. If two files have the same name (even if they are relative paths) and are used in different protoc commands, they'll conflict in the registry. Since protobuf file generation doesn't work very well with `paths=source_relative`, this removes the `go:generate` expression and just relies on the dockerfile to perform the generation. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
78 lines
1.5 KiB
Go
78 lines
1.5 KiB
Go
package errdefs
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
|
|
"github.com/containerd/typeurl/v2"
|
|
"github.com/golang/protobuf/jsonpb" //nolint:staticcheck
|
|
"github.com/moby/buildkit/solver/pb"
|
|
"github.com/moby/buildkit/util/grpcerrors"
|
|
)
|
|
|
|
func init() {
|
|
typeurl.Register((*Solve)(nil), "github.com/moby/buildkit", "errdefs.Solve+json")
|
|
}
|
|
|
|
//nolint:revive
|
|
type IsSolve_Subject isSolve_Subject
|
|
|
|
// SolveError will be returned when an error is encountered during a solve that
|
|
// has an exec op.
|
|
type SolveError struct {
|
|
*Solve
|
|
Err error
|
|
}
|
|
|
|
func (e *SolveError) Error() string {
|
|
return e.Err.Error()
|
|
}
|
|
|
|
func (e *SolveError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
func (e *SolveError) ToProto() grpcerrors.TypedErrorProto {
|
|
return e.Solve
|
|
}
|
|
|
|
func WithSolveError(err error, subject IsSolve_Subject, inputIDs, mountIDs []string) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
var (
|
|
oe *OpError
|
|
op *pb.Op
|
|
description map[string]string
|
|
)
|
|
if errors.As(err, &oe) {
|
|
op = oe.Op
|
|
description = oe.Description
|
|
}
|
|
return &SolveError{
|
|
Err: err,
|
|
Solve: &Solve{
|
|
InputIDs: inputIDs,
|
|
MountIDs: mountIDs,
|
|
Op: op,
|
|
Subject: subject,
|
|
Description: description,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (v *Solve) WrapError(err error) error {
|
|
return &SolveError{Err: err, Solve: v}
|
|
}
|
|
|
|
func (v *Solve) MarshalJSON() ([]byte, error) {
|
|
m := jsonpb.Marshaler{}
|
|
buf := new(bytes.Buffer)
|
|
err := m.Marshal(buf, v)
|
|
return buf.Bytes(), err
|
|
}
|
|
|
|
func (v *Solve) UnmarshalJSON(b []byte) error {
|
|
return jsonpb.Unmarshal(bytes.NewReader(b), v)
|
|
}
|