Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions v1/providers/nebius/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1
import (
"fmt"

v1 "github.com/brevdev/cloud/v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -30,6 +31,20 @@ func isNotFoundError(err error) bool {
return false
}

func handleErrToCloudErr(e error) error {
if e == nil {
return nil
}

// Check for gRPC ResourceExhausted status code
if grpcStatus, ok := status.FromError(e); ok {
if grpcStatus.Code() == codes.ResourceExhausted {
return v1.ErrOutOfQuota
}
}
return e
}

// isAlreadyExistsError checks if an error is an "already exists" error
//
//nolint:unused // Reserved for future error handling improvements
Expand Down
7 changes: 4 additions & 3 deletions v1/providers/nebius/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,18 @@ func (c *NebiusClient) CreateInstance(ctx context.Context, attrs v1.CreateInstan

operation, err := c.sdk.Services().Compute().V1().Instance().Create(ctx, createReq)
if err != nil {
return nil, errors.WrapAndTrace(err)
return nil, errors.WrapAndTrace(handleErrToCloudErr(err))
}

// Wait for the operation to complete and get the actual instance ID
finalOp, err := operation.Wait(ctx)
if err != nil {
return nil, errors.WrapAndTrace(err)
return nil, errors.WrapAndTrace(handleErrToCloudErr(err))
}

if !finalOp.Successful() {
return nil, fmt.Errorf("instance creation failed: %v", finalOp.Status())
statusErr := fmt.Errorf("instance creation failed: %v", finalOp.Status())
return nil, handleErrToCloudErr(statusErr)
}

// Get the actual instance ID from the completed operation
Expand Down
Loading