Skip to content

Commit

Permalink
Merge pull request #5163 from tonistiigi/history-graphstate-errors-in…
Browse files Browse the repository at this point in the history
…ternal

solver: mark history and graph concistency errors as internal
  • Loading branch information
thompson-shaun authored Jul 25, 2024
2 parents 3d1dc77 + 5149ea8 commit 7c025bf
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
31 changes: 31 additions & 0 deletions errdefs/errdefs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package errdefs

import "errors"

type internalErr struct {
error
}

func (internalErr) System() {}

func (err internalErr) Unwrap() error {
return err.error
}

type system interface {
System()
}

var _ system = internalErr{}

func Internal(err error) error {
if err == nil {
return nil
}
return internalErr{err}
}

func IsInternal(err error) bool {
var s system
return errors.As(err, &s)
}
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 @@ -371,7 +372,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 Down Expand Up @@ -399,7 +401,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 7c025bf

Please sign in to comment.