Skip to content

Commit bcd0710

Browse files
authored
fix(nebius): add create-instance error handling for ResourceExhausted (#93)
* fix(nebius): add create-instance error handling for ResourceExhausted * chore:package added * fix: lint error
1 parent ccc63c8 commit bcd0710

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

v1/providers/nebius/errors.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package v1
33
import (
44
"fmt"
55

6+
v1 "github.com/brevdev/cloud/v1"
67
"google.golang.org/grpc/codes"
78
"google.golang.org/grpc/status"
89
)
@@ -30,6 +31,20 @@ func isNotFoundError(err error) bool {
3031
return false
3132
}
3233

34+
func handleErrToCloudErr(e error) error {
35+
if e == nil {
36+
return nil
37+
}
38+
39+
// Check for gRPC ResourceExhausted status code
40+
if grpcStatus, ok := status.FromError(e); ok {
41+
if grpcStatus.Code() == codes.ResourceExhausted {
42+
return v1.ErrOutOfQuota
43+
}
44+
}
45+
return e
46+
}
47+
3348
// isAlreadyExistsError checks if an error is an "already exists" error
3449
//
3550
//nolint:unused // Reserved for future error handling improvements

v1/providers/nebius/instance.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,18 @@ func (c *NebiusClient) CreateInstance(ctx context.Context, attrs v1.CreateInstan
143143

144144
operation, err := c.sdk.Services().Compute().V1().Instance().Create(ctx, createReq)
145145
if err != nil {
146-
return nil, errors.WrapAndTrace(err)
146+
return nil, errors.WrapAndTrace(handleErrToCloudErr(err))
147147
}
148148

149149
// Wait for the operation to complete and get the actual instance ID
150150
finalOp, err := operation.Wait(ctx)
151151
if err != nil {
152-
return nil, errors.WrapAndTrace(err)
152+
return nil, errors.WrapAndTrace(handleErrToCloudErr(err))
153153
}
154154

155155
if !finalOp.Successful() {
156-
return nil, fmt.Errorf("instance creation failed: %v", finalOp.Status())
156+
statusErr := fmt.Errorf("instance creation failed: %v", finalOp.Status())
157+
return nil, handleErrToCloudErr(statusErr)
157158
}
158159

159160
// Get the actual instance ID from the completed operation

0 commit comments

Comments
 (0)