Skip to content

Commit 80ca4be

Browse files
authored
Merge pull request moby#4154 from crazy-max/ctrl-status-notfound
2 parents 3c7fcf1 + 262d58a commit 80ca4be

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

client/build_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/moby/buildkit/solver/errdefs"
2424
"github.com/moby/buildkit/solver/pb"
2525
"github.com/moby/buildkit/util/entitlements"
26+
"github.com/moby/buildkit/util/grpcerrors"
2627
utilsystem "github.com/moby/buildkit/util/system"
2728
"github.com/moby/buildkit/util/testutil/echoserver"
2829
"github.com/moby/buildkit/util/testutil/integration"
@@ -31,6 +32,7 @@ import (
3132
"github.com/pkg/errors"
3233
"github.com/stretchr/testify/require"
3334
"golang.org/x/crypto/ssh/agent"
35+
"google.golang.org/grpc/codes"
3436
)
3537

3638
func TestClientGatewayIntegration(t *testing.T) {
@@ -334,6 +336,7 @@ func testUnknownBuildID(t *testing.T, sb integration.Sandbox) {
334336
_, err = g.Ping(ctx, &gatewayapi.PingRequest{})
335337
require.Error(t, err)
336338
require.Contains(t, err.Error(), "no such job")
339+
require.Equal(t, grpcerrors.Code(err), codes.NotFound)
337340
}
338341

339342
// testClientGatewayContainerCancelOnRelease is testing that all running

control/gateway/gateway.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/moby/buildkit/client/buildid"
99
"github.com/moby/buildkit/frontend/gateway"
1010
gwapi "github.com/moby/buildkit/frontend/gateway/pb"
11+
"github.com/moby/buildkit/solver/errdefs"
1112
"github.com/pkg/errors"
1213
"google.golang.org/grpc"
1314
)
@@ -73,7 +74,7 @@ func (gwf *GatewayForwarder) lookupForwarder(ctx context.Context) (gateway.LLBBr
7374
for {
7475
select {
7576
case <-ctx.Done():
76-
return nil, errors.Errorf("no such job %s", bid)
77+
return nil, errdefs.NewUnknownJobError(bid)
7778
default:
7879
}
7980
fwd, ok := gwf.builds[bid]

solver/errdefs/jobs.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package errdefs
2+
3+
import (
4+
"fmt"
5+
6+
"google.golang.org/grpc/codes"
7+
)
8+
9+
type UnknownJobError struct {
10+
id string
11+
}
12+
13+
func (e *UnknownJobError) Code() codes.Code {
14+
return codes.NotFound
15+
}
16+
17+
func (e *UnknownJobError) Error() string {
18+
return fmt.Sprintf("no such job %s", e.id)
19+
}
20+
21+
func NewUnknownJobError(id string) error {
22+
return &UnknownJobError{id: id}
23+
}

solver/jobs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ func (jl *Solver) Get(id string) (*Job, error) {
484484
for {
485485
select {
486486
case <-ctx.Done():
487-
return nil, errors.Errorf("no such job %s", id)
487+
return nil, errdefs.NewUnknownJobError(id)
488488
default:
489489
}
490490
j, ok := jl.jobs[id]

solver/scheduler_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,6 +3315,17 @@ func TestInputRequestDeadlock(t *testing.T) {
33153315
j2 = nil
33163316
}
33173317

3318+
func TestUnknownBuildID(t *testing.T) {
3319+
s := NewSolver(SolverOpt{
3320+
ResolveOpFunc: testOpResolver,
3321+
})
3322+
defer s.Close()
3323+
3324+
_, err := s.Get(identity.NewID())
3325+
require.Error(t, err)
3326+
require.Contains(t, err.Error(), "no such job")
3327+
}
3328+
33183329
func generateSubGraph(nodes int) (Edge, int) {
33193330
if nodes == 1 {
33203331
value := rand.Int() % 500 //nolint:gosec

0 commit comments

Comments
 (0)