Skip to content

Commit

Permalink
solver: mark history and graph concistency errors as internal
Browse files Browse the repository at this point in the history
Error during creating history or failure in graph concistency
checks are signs of either bugs or system configuration issue. This
makes sure that gRPC error code in the API error based on these
cases has correct value to signify it.

Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Jul 17, 2024
1 parent 8f4aa21 commit f66c03b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
24 changes: 24 additions & 0 deletions errdefs/errdefs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package errdefs

import "errors"

type internalErr struct {
error
}

func (internalErr) System() {}

type system interface {
System()
}

var _ system = internalErr{}

func Internal(err error) error {
return internalErr{err}
}

func IsInternal(err error) bool {
var s system
return errors.As(err, &s)
}
3 changes: 2 additions & 1 deletion solver/llbsolver/ops/opsutils/contenthash.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path"

"github.com/moby/buildkit/cache/contenthash"
"github.com/moby/buildkit/errdefs"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/solver"
"github.com/moby/buildkit/worker"
Expand Down Expand Up @@ -55,7 +56,7 @@ func NewContentHashFunc(selectors []Selector) solver.ResultBasedCacheFunc {
s,
)
if err != nil {
return errors.Wrapf(err, "failed to calculate checksum of ref %s", ref.ID())
return errdefs.Internal(errors.Wrapf(err, "failed to calculate checksum of ref %s", ref.ID()))
}
dgsts[i] = []byte(dgst)
return nil
Expand Down
10 changes: 6 additions & 4 deletions solver/llbsolver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/moby/buildkit/cache/remotecache"
"github.com/moby/buildkit/client"
controlgateway "github.com/moby/buildkit/control/gateway"
"github.com/moby/buildkit/errdefs"
"github.com/moby/buildkit/executor/resources"
resourcestypes "github.com/moby/buildkit/executor/resources/types"
"github.com/moby/buildkit/exporter"
Expand Down Expand Up @@ -158,7 +159,7 @@ func (s *Solver) Bridge(b solver.Builder) frontend.FrontendLLBBridge {
func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend.SolveRequest, exp ExporterRequest, j *solver.Job, usage *resources.SysSampler) (func(context.Context, *Result, []exporter.DescriptorReference, error) error, error) {
stopTrace, err := detect.Recorder.Record(ctx)
if err != nil {
return nil, err
return nil, errdefs.Internal(err)
}

st := time.Now()
Expand All @@ -183,7 +184,7 @@ func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend
if stopTrace != nil {
stopTrace()
}
return nil, err
return nil, errdefs.Internal(err)
}

return func(ctx context.Context, res *Result, descrefs []exporter.DescriptorReference, err error) error {
Expand Down Expand Up @@ -370,7 +371,8 @@ func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend
})
}
if err1 := eg.Wait(); err == nil {
err = err1
// any error from exporting history record is internal
err = errdefs.Internal(err1)
}

defer func() {
Expand All @@ -397,7 +399,7 @@ func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend
Record: rec,
}); err1 != nil {
if err == nil {
err = err1
err = errdefs.Internal(err1)
}
}

Expand Down
3 changes: 2 additions & 1 deletion solver/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"sync"

"github.com/moby/buildkit/errdefs"
"github.com/moby/buildkit/solver/internal/pipe"
"github.com/moby/buildkit/util/bklog"
"github.com/moby/buildkit/util/cond"
Expand Down Expand Up @@ -403,7 +404,7 @@ func (pf *pipeFactory) NewInputRequest(ee Edge, req *edgeRequest) pipe.Receiver
WithField("edge_index", ee.Index).
Error("failed to get edge: inconsistent graph state")
return pf.NewFuncRequest(func(_ context.Context) (interface{}, error) {
return nil, errors.Errorf("failed to get edge: inconsistent graph state in edge %s %s %d", ee.Vertex.Name(), ee.Vertex.Digest(), ee.Index)
return nil, errdefs.Internal(errors.Errorf("failed to get edge: inconsistent graph state in edge %s %s %d", ee.Vertex.Name(), ee.Vertex.Digest(), ee.Index))
})
}
p := pf.s.newPipe(target, pf.e, pipe.Request{Payload: req})
Expand Down
5 changes: 5 additions & 0 deletions util/grpcerrors/grpcerrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
gogotypes "github.com/gogo/protobuf/types"
"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/golang/protobuf/ptypes/any"
"github.com/moby/buildkit/errdefs"
"github.com/moby/buildkit/util/bklog"
"github.com/moby/buildkit/util/stack"
spb "google.golang.org/genproto/googleapis/rpc/status"
Expand Down Expand Up @@ -94,6 +95,10 @@ func withDetails(ctx context.Context, s *status.Status, details ...proto.Message
}

func Code(err error) codes.Code {
if errdefs.IsInternal(err) {
return codes.Internal
}

if se, ok := err.(interface {
Code() codes.Code
}); ok {
Expand Down

0 comments on commit f66c03b

Please sign in to comment.