Skip to content

Errors and retries

Every API error carries:

  • code
  • status
  • request_id
  • retryable
  • retry_after_seconds
  • the number of attempts made

Each error kind has its own class, so you can catch exactly what you handle.

import uuid
from svm import ApiError, Sandbox
from svm.errors import SandboxFileNotFoundError, SandboxNotFoundError
try:
Sandbox.connect(str(uuid.uuid4()))
except SandboxNotFoundError as error:
# Every API failure is an ApiError: HTTP status, error code, message and request id.
assert isinstance(error, ApiError)
print(error.status_code, error.code, error.message, error.request_id)
with Sandbox.create(template="base") as sandbox:
try:
sandbox.files.read_text("/no/such/file")
except SandboxFileNotFoundError as error:
print("missing file:", error.status_code, error.code)
# A command that runs past timeout_seconds is killed; the result says so.
result = sandbox.commands.run("sleep 30", timeout_seconds=2)
print("timed out:", result.timed_out)
Kind Code Python and TypeScript Go errors.Is
authentication UNAUTHENTICATED AuthenticationError ErrAuthentication
permission denied PERMISSION_DENIED PermissionDeniedError ErrPermissionDenied
not found NOT_FOUND NotFoundError ErrNotFound
conflict ALREADY_EXISTS, IDEMPOTENCY_CONFLICT ConflictError ErrConflict
precondition FAILED_PRECONDITION, SANDBOX_NOT_RUNNING, SANDBOX_PAUSED, TEMPLATE_NOT_READY PreconditionError ErrPrecondition
invalid argument INVALID_ARGUMENT InvalidArgumentError ErrInvalidArgument
rate limited RATE_LIMITED RateLimitedError ErrRateLimited
quota exceeded QUOTA_EXCEEDED, RESOURCE_EXHAUSTED QuotaExceededError ErrQuotaExceeded
billing blocked BILLING_BLOCKED BillingBlockedError ErrBillingBlocked
unavailable UNAVAILABLE UnavailableError ErrUnavailable
timeout no answer in time, or a wait that gave up TimeoutError ErrTimeout
transport connection failed or reset TransportError ErrTransport

Ruby uses the Python class names under SVM::. Java nests them in ApiException (ApiException.NotFound).

Specific subclasses name what is missing or full. Each is also its general kind, so catching NotFoundError still works:

  • SandboxNotFoundError
  • VolumeNotFoundError
  • SecretNotFoundError
  • the file-not-found error
  • NotEnoughSpaceError
  • SandboxNotRunningError
  • TemplateError
  • BuildError
Situation Retried
A GET, HEAD, PUT or DELETE that failed to connect, timed out, or got 502, 503 or 504 Yes
A POST that failed the same way Yes, with the same idempotency key, so it cannot create twice
429 RATE_LIMITED Yes, after the server’s Retry-After
Other 4xx, QUOTA_EXCEEDED, BILLING_BLOCKED Never
500 INTERNAL Only when the error says retryable

The default is six attempts with jittered exponential backoff (250 ms doubling up to 8 s), and a 10-second timeout per attempt.