Skip to content

Commit 66fa7da

Browse files
committed
Handle 'Sandbox not found' errors in orchestrator operations
1 parent 42288c5 commit 66fa7da

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/api/internal/orchestrator/keep_alive.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ func (o *Orchestrator) KeepAliveFor(ctx context.Context, sandboxID string, durat
5757
}
5858
err = o.UpdateSandbox(ctx, sandboxID, sbx.EndTime, sbx.ClusterID, sbx.NodeID)
5959
if err != nil {
60+
if errors.Is(err, ErrSandboxNotFound) {
61+
return &api.APIError{Code: http.StatusNotFound, ClientMsg: "Sandbox not found", Err: err}
62+
}
63+
6064
return &api.APIError{Code: http.StatusInternalServerError, ClientMsg: "Error when setting sandbox timeout", Err: err}
6165
}
6266

packages/api/internal/orchestrator/update_instance.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import (
66
"fmt"
77
"time"
88

9+
"github.com/e2b-dev/infra/packages/api/internal/utils"
910
"github.com/google/uuid"
1011
"go.opentelemetry.io/otel/attribute"
1112
"go.opentelemetry.io/otel/trace"
13+
"google.golang.org/grpc/codes"
14+
"google.golang.org/grpc/status"
1215
"google.golang.org/protobuf/types/known/timestamppb"
1316

14-
"github.com/e2b-dev/infra/packages/api/internal/utils"
1517
"github.com/e2b-dev/infra/packages/shared/pkg/grpc/orchestrator"
1618
"github.com/e2b-dev/infra/packages/shared/pkg/telemetry"
1719
)
@@ -41,9 +43,13 @@ func (o *Orchestrator) UpdateSandbox(
4143
EndTime: timestamppb.New(endTime),
4244
},
4345
)
44-
45-
err = utils.UnwrapGRPCError(err)
4646
if err != nil {
47+
grpcErr, ok := status.FromError(err)
48+
if ok && grpcErr.Code() == codes.NotFound {
49+
return ErrSandboxNotFound
50+
}
51+
52+
err = utils.UnwrapGRPCError(err)
4753
return fmt.Errorf("failed to update sandbox '%s': %w", sandboxID, err)
4854
}
4955

0 commit comments

Comments
 (0)