feat(ruby): map core errors to typed exception classes - #1455
Conversation
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0328a342d2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Raise a `Microsandbox::Error` subclass matching the core `MicrosandboxError`
variant instead of the base class for everything. The class names and
`#code` strings mirror the Python SDK (`sdk/python/microsandbox/errors.py`),
extended with the Go SDK's per-variant coverage for snapshots, exec spawn
failures, and duplicate volumes. Variants without a dedicated class still
raise `Microsandbox::Error`, so existing `rescue Microsandbox::Error` code
keeps catching everything; argument validation keeps raising `ArgumentError`
and `TypeError`.
`lib/microsandbox/errors.rb` reopens the natively defined base class to add
`Error.code` / `Error#code` and defines the flat class table. The native
extension gains a `core_error` mapping used by `run()` and the backend
selection helpers; `Unsupported { op, reason }` renders the Ruby API name
(`sandbox.create` rather than `Sandbox::create`) and attaches
`UnsupportedError#operation` / `#hint`, as the Python bridge does.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Aojf59DyiLvVeQnCy3R9ft
0328a34 to
fd1d67e
Compare
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fd1d67e857
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // ------------------------------------------------------------------------------------------------- | ||
| // Core error mapping | ||
| // ------------------------------------------------------------------------------------------------- |
There was a problem hiding this comment.
Put error helpers under the required Functions section
This newly added section contains free functions but uses the unqualified Core error mapping label instead of the repository-required Functions/Functions: ... organization. Rename it to an approved qualified Functions section so the extension follows the mandated Rust layout.
AGENTS.md reference: AGENTS.md:L198-L204
Useful? React with 👍 / 👎.
|
TL;DR
The Ruby SDK now raises typed
Microsandbox::Errorsubclasses (with stable#codestrings) that mirror the Python SDK, so callers can rescue specific failures instead of matching message text.Description
Microsandbox::Error, so existingrescue Microsandbox::Errorcode keeps catching all of them. Argument validation is unchanged and outside that guarantee: unknown keywords and wrongly typed values keep raisingArgumentError/TypeErrorbefore any operation runs.lib/microsandbox/errors.rbreopens the natively definedMicrosandbox::Errorto addError.code/Error#code("microsandbox-error") and defines a flat table of direct subclasses via a privatedefine_error(name, code)factory.UnsupportedErrorgains#operation/#hintreaders.sdk/python/microsandbox/errors.pyexactly:InvalidConfigError,NoDefaultCommandError,CloudHttpError,SandboxNotFoundError,SandboxNotRunningError,SandboxAlreadyExistsError,SandboxStillRunningError,ExecTimeoutError,ExecFailedError,FilesystemError,PathNotFoundError,VolumeNotFoundError,ImageNotFoundError,ImageInUseError,ImagePullFailedError,NetworkPolicyError,SecretViolationError,TlsError,IoError,MetricsDisabledError,MetricsUnavailableError,UnsupportedOperationError,UnsupportedError,SnapshotMigrationError.SnapshotNotFoundError,SnapshotAlreadyExistsError,SnapshotSandboxRunningError,SnapshotImageMissingError,SnapshotIntegrityError, andVolumeAlreadyExistsError.ext/microsandbox/src/lib.rs, new "Core error mapping" section):core_errormatches theMicrosandboxErrorvariant to a class and looks it up on theMicrosandboxmodule, falling back toError(thenRuntimeError) if a constant is missing.run(), the backend-selection helpers, and thenetwork:policy builder (whoseBuildErroris converted through core'sFromimpl intoNetworkBuilder) all use it, so the oldnative_errorhelper is gone.InvalidConfig→InvalidConfigError;NoDefaultCommand→NoDefaultCommandError;CloudHttp→CloudHttpError;SandboxNotFound/SandboxNotRunning/SandboxAlreadyExists/SandboxStillRunning→ the matchingSandbox*Error;ExecTimeout→ExecTimeoutError;ExecFailed→ExecFailedError(Python defines this class but does not wire the variant; Ruby does);SandboxFsOps→FilesystemError;VolumeNotFound/VolumeAlreadyExists→Volume*Error;ImageNotFound/ImageInUse→Image*Error; the fiveSnapshot*variants andSnapshotMigration→ the matchingSnapshot*Error;NetworkBuilder→NetworkPolicyError;Io→IoError;MetricsDisabled/MetricsUnavailable→Metrics*Error;AgentClient(UnsupportedOperation)→UnsupportedOperationError;Unsupported→UnsupportedError.Http,Database,Runtime,BootStart,Terminal,Custom, ...) still raiseMicrosandbox::Error.PathNotFoundError,ImagePullFailedError,SecretViolationError, andTlsErrorare defined for parity but have no core variant today.Unsupported { op, reason }renders the Ruby API name, as the Python bridge renders the Python one:sandbox.create is not supported by this backend: the replace option is not accepted here, witherror.operation == "sandbox.create"anderror.hint == "the replace option is not accepted here".#code,UnsupportedErrorattributes) and the supported-surface paragraph mentions typed errors.InvalidConfigErrorfor an empty sandbox name (and thatrescue Microsandbox::Errorstill catches it),NetworkPolicyErrorfor a malformedallowed_hostsentry,SandboxNotFoundErrorfromSandbox.geton a missing name, andUnsupportedError#operation/#hintthrough the cloud backend's request-building rejection (no network involved; the backend switch runs in a separate Ruby process so the test process keeps its backend selection). Integration tests coverExecTimeoutError,FilesystemError,VolumeNotFoundError, andSandboxStillRunningErroron real microVMs.Test Plan
cd sdk/ruby/ext/microsandbox && rustup run stable cargo fmt -- --check && rustup run stable cargo clippy --profile ci -- -D warnings: clean (cargo 1.96.0).cd sdk/ruby && rustup run stable rake test(unit,MSB_RUBY_INTEGRATIONunset): 29 tests, 95 assertions, 0 failures, 0 errors, 11 omissions (the integration tests skipping).cd sdk/ruby && MSB_RUBY_INTEGRATION=1 MSB_RUBY_TEST_IMAGE=public.ecr.aws/docker/library/alpine:latest rustup run stable rake teston an Apple Silicon host with the 0.6.14 runtime (ruby -Ilib -e 'require "microsandbox"; Microsandbox.install unless Microsandbox.installed?'): 28 tests, 116 assertions, 0 failures, 0 errors, 0 omissions.ext/microsandbox/Cargo.lockis untouched by this PR.Generated with Claude Code
https://claude.ai/code/session_01RqjuPiGZ34s5CPfayN8JN4