Make fault: a first-class argument to raise#537
Merged
Conversation
bde92e7 to
eba23b4
Compare
selviarora
approved these changes
Jun 10, 2026
donk-shopify
approved these changes
Jun 10, 2026
eba23b4 to
37c8faf
Compare
Add a `fault:` keyword argument to `Dev::Error#initialize` and
`CLI::Kit.raise`, allowing callers to attribute exceptions to a fault
category at the raise site:
raise Dev::IncorrectUsage.new("bad input", fault: Fault::USER)
CLI::Kit.raise(SomeError, "failed", fault: Fault::SYSTEM)
The `fault:` kwarg on Dev::Error is optional at runtime (defaults to
nil, falling back to the subclass's `def fault` default) so that
raising can never itself fail — better to raise with a default fault
than to raise an ArgumentError while trying to raise the real error.
The RequireExplicitRaise cop is updated to enforce fault attribution:
- `raise Klass, "msg"` is now banned (Sorbet's Kernel#raise intrinsic
cannot be extended with fault:). The cop suggests using
`raise MyError.new(..., fault: ...)` for Dev::Error subclasses, or
`CLI::Kit.raise ..., fault: ...` for non-Dev::Error subclasses.
- `raise Klass.new("msg")` without fault: is flagged.
- `CLI::Kit.raise(Klass, "msg")` without fault: is flagged.
- `raise RuntimeError.new(...)` is flagged (use a specific class).
- `raise Klass.new(fault: ...)` without a message is flagged.
The cop is rewritten to use RuboCop node patterns throughout.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
37c8faf to
a2a3a0a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
fault:keyword argument toCLI::Kit.raise, letting callers attribute an exception to a fault category at the raise site:Introduces an
Exception::Faulthierarchy (System,ImplicitlySystem,Project,User,Terroir) plus anException#fault/#fault!/#with_faultprotocol.bug?now derives from the fault (Fault::System === fault) instead of being hardcodedtrue, so an unattributed exception still defaults tobug? == trueviaImplicitlySystem(aSystemsubclass). This keeps existing behavior fully backward compatible.Ruby stdlib exceptions that the runtime raises itself, and so have no raise site to annotate (
Interrupt,SignalException,Errno::ENOSPC,Errno::EPIPE,Errno::EIO), get a class-level default fault ofTerroir. TheErrorHandlerInterrupt/ENOSPC paths now passfault: Exception::Fault::TERROIRinstead ofbug: false, which is equivalent (Terroiris not aSystem, sobug?isfalse).Also dropping 3.1 support to make endless methods viable.