Skip to content

Commit 5149ea8

Browse files
committed
solver: mark history and graph concistency errors as internal
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]>
1 parent 8f4aa21 commit 5149ea8

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

errdefs/errdefs.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package errdefs
2+
3+
import "errors"
4+
5+
type internalErr struct {
6+
error
7+
}
8+
9+
func (internalErr) System() {}
10+
11+
func (err internalErr) Unwrap() error {
12+
return err.error
13+
}
14+
15+
type system interface {
16+
System()
17+
}
18+
19+
var _ system = internalErr{}
20+
21+
func Internal(err error) error {
22+
if err == nil {
23+
return nil
24+
}
25+
return internalErr{err}
26+
}
27+
28+
func IsInternal(err error) bool {
29+
var s system
30+
return errors.As(err, &s)
31+
}

solver/llbsolver/solver.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/moby/buildkit/cache/remotecache"
1919
"github.com/moby/buildkit/client"
2020
controlgateway "github.com/moby/buildkit/control/gateway"
21+
"github.com/moby/buildkit/errdefs"
2122
"github.com/moby/buildkit/executor/resources"
2223
resourcestypes "github.com/moby/buildkit/executor/resources/types"
2324
"github.com/moby/buildkit/exporter"
@@ -158,7 +159,7 @@ func (s *Solver) Bridge(b solver.Builder) frontend.FrontendLLBBridge {
158159
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) {
159160
stopTrace, err := detect.Recorder.Record(ctx)
160161
if err != nil {
161-
return nil, err
162+
return nil, errdefs.Internal(err)
162163
}
163164

164165
st := time.Now()
@@ -183,7 +184,7 @@ func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend
183184
if stopTrace != nil {
184185
stopTrace()
185186
}
186-
return nil, err
187+
return nil, errdefs.Internal(err)
187188
}
188189

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

376378
defer func() {
@@ -397,7 +399,7 @@ func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend
397399
Record: rec,
398400
}); err1 != nil {
399401
if err == nil {
400-
err = err1
402+
err = errdefs.Internal(err1)
401403
}
402404
}
403405

solver/scheduler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"sync"
77

8+
"github.com/moby/buildkit/errdefs"
89
"github.com/moby/buildkit/solver/internal/pipe"
910
"github.com/moby/buildkit/util/bklog"
1011
"github.com/moby/buildkit/util/cond"
@@ -403,7 +404,7 @@ func (pf *pipeFactory) NewInputRequest(ee Edge, req *edgeRequest) pipe.Receiver
403404
WithField("edge_index", ee.Index).
404405
Error("failed to get edge: inconsistent graph state")
405406
return pf.NewFuncRequest(func(_ context.Context) (interface{}, error) {
406-
return nil, errors.Errorf("failed to get edge: inconsistent graph state in edge %s %s %d", ee.Vertex.Name(), ee.Vertex.Digest(), ee.Index)
407+
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))
407408
})
408409
}
409410
p := pf.s.newPipe(target, pf.e, pipe.Request{Payload: req})

util/grpcerrors/grpcerrors.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
gogotypes "github.com/gogo/protobuf/types"
1111
"github.com/golang/protobuf/proto" //nolint:staticcheck
1212
"github.com/golang/protobuf/ptypes/any"
13+
"github.com/moby/buildkit/errdefs"
1314
"github.com/moby/buildkit/util/bklog"
1415
"github.com/moby/buildkit/util/stack"
1516
spb "google.golang.org/genproto/googleapis/rpc/status"
@@ -94,6 +95,10 @@ func withDetails(ctx context.Context, s *status.Status, details ...proto.Message
9495
}
9596

9697
func Code(err error) codes.Code {
98+
if errdefs.IsInternal(err) {
99+
return codes.Internal
100+
}
101+
97102
if se, ok := err.(interface {
98103
Code() codes.Code
99104
}); ok {

0 commit comments

Comments
 (0)