gateway: fix error details passing through gateway

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
v0.8
Tonis Tiigi 2020-04-21 14:05:49 -07:00
parent 3f77f0495b
commit e4cc0866f5
4 changed files with 46 additions and 5 deletions

View File

@ -13,6 +13,8 @@ import (
"time"
"github.com/docker/distribution/reference"
gogotypes "github.com/gogo/protobuf/types"
"github.com/golang/protobuf/ptypes/any"
apitypes "github.com/moby/buildkit/api/types"
"github.com/moby/buildkit/cache"
cacheutil "github.com/moby/buildkit/cache/util"
@ -25,6 +27,7 @@ import (
"github.com/moby/buildkit/identity"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/solver"
"github.com/moby/buildkit/solver/errdefs"
opspb "github.com/moby/buildkit/solver/pb"
"github.com/moby/buildkit/util/apicaps"
"github.com/moby/buildkit/util/tracing"
@ -670,11 +673,11 @@ func (lbf *llbBridgeForwarder) Ping(context.Context, *pb.PingRequest) (*pb.PongR
func (lbf *llbBridgeForwarder) Return(ctx context.Context, in *pb.ReturnRequest) (*pb.ReturnResponse, error) {
if in.Error != nil {
return lbf.setResult(nil, status.ErrorProto(&spb.Status{
return lbf.setResult(nil, errdefs.FromGRPC(status.ErrorProto(&spb.Status{
Code: in.Error.Code,
Message: in.Error.Message,
// Details: in.Error.Details,
}))
Details: convertGogoAny(in.Error.Details),
})))
} else {
r := &frontend.Result{
Metadata: in.Result.Metadata,
@ -754,3 +757,11 @@ type markTypeFrontend struct{}
func (*markTypeFrontend) SetImageOption(ii *llb.ImageInfo) {
ii.RecordType = string(client.UsageRecordTypeFrontend)
}
func convertGogoAny(in []*gogotypes.Any) []*any.Any {
out := make([]*any.Any, len(in))
for i := range in {
out[i] = &any.Any{TypeUrl: in[i].TypeUrl, Value: in[i].Value}
}
return out
}

View File

@ -10,9 +10,12 @@ import (
"time"
"github.com/gogo/googleapis/google/rpc"
gogotypes "github.com/gogo/protobuf/types"
"github.com/golang/protobuf/ptypes/any"
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/frontend/gateway/client"
pb "github.com/moby/buildkit/frontend/gateway/pb"
"github.com/moby/buildkit/solver/errdefs"
opspb "github.com/moby/buildkit/solver/pb"
"github.com/moby/buildkit/util/apicaps"
digest "github.com/opencontainers/go-digest"
@ -150,12 +153,12 @@ func (c *grpcClient) Run(ctx context.Context, f client.BuildFunc) (retError erro
}
}
if retError != nil {
st, _ := status.FromError(errors.Cause(retError))
st, _ := status.FromError(errdefs.ToGRPC(retError))
stp := st.Proto()
req.Error = &rpc.Status{
Code: stp.Code,
Message: stp.Message,
// Details: stp.Details,
Details: convertToGogoAny(stp.Details),
}
}
if _, err := c.client.Return(ctx, req); err != nil && retError == nil {
@ -589,3 +592,11 @@ func workers() []client.WorkerInfo {
func product() string {
return os.Getenv("BUILDKIT_EXPORTEDPRODUCT")
}
func convertToGogoAny(in []*any.Any) []*gogotypes.Any {
out := make([]*gogotypes.Any, len(in))
for i := range in {
out[i] = &gogotypes.Any{TypeUrl: in[i].TypeUrl, Value: in[i].Value}
}
return out
}

View File

@ -3,6 +3,7 @@ package errdefs
import (
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/pkg/errors"
spb "google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@ -122,6 +123,10 @@ func FromGRPC(err error) error {
}
}
if !hasLocalStackTrace(err) {
err = errors.WithStack(err)
}
return err
}

View File

@ -40,6 +40,20 @@ func Traces(err error) []*Stack {
return st
}
func hasLocalStackTrace(err error) bool {
wrapped, ok := err.(interface {
Unwrap() error
})
if ok && hasLocalStackTrace(wrapped.Unwrap()) {
return true
}
_, ok = err.(interface {
StackTrace() errors.StackTrace
})
return ok
}
func StackFormatter(err error) fmt.Formatter {
return &stackFormatter{err}
}