feat(errors): expose RFC-0003 structured failures - #52
Merged
Conversation
Reviewer's GuideThis PR implements RFC-0003 structured failure envelopes end to end: Rust errors gain stable codes and contextual metadata, Python exposes typed ValueError-compatible exceptions, the CLI supports machine-readable JSON failures, and documentation plus schema-backed tests define and validate the boundary. Sequence diagram for structured Python error propagationsequenceDiagram
participant Caller
participant OneRoll
participant RustCore
participant DiceParser
participant DiceCalculator
Caller->>OneRoll: roll(expression)
OneRoll->>RustCore: _roll_dice(expression)
RustCore->>DiceParser: parse_expression(expression)
DiceParser-->>RustCore: DiceError
RustCore-->>OneRoll: PyValueError with _oneroll_error_json
OneRoll->>OneRoll: _raise_structured(error)
OneRoll-->>Caller: ParseError or typed OneRollError
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
6 tasks
HsiangNianian
enabled auto-merge
August 28, 2026 06:01
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/calculator.rs" line_range="418-432" />
<code_context>
- self.charge_output_items_for_rolls(&rolls)?;
- self.charge_serialized_output(&rolls)?;
- Ok(rolls)
+ let result = (|| {
+ self.charge_instruction_activation()?;
+ let rolls = self.roll_dice_with_budget(dice)?;
+ self.charge_output_items_for_rolls(&rolls)?;
+ self.charge_serialized_output(&rolls)?;
+ Ok(rolls)
+ })();
+ self.attach_random_context(result)
}
</code_context>
<issue_to_address>
**issue (broader_impact):** Batch evaluation failures never include the `batch` metadata that the Python exception hierarchy parses and exposes: `evaluate_batch` attaches only random metadata, so `OneRollError.batch` is always `None` for `roll_multiple` failures and callers cannot identify the failed sample or total sample count.
**Triggers:** When a batch operation fails after evaluation has started, such as `roll_multiple("1 / 0", 2)`.
**Suggested fix:** Attach a batch descriptor containing the algorithm, seed, sample count, and failing sample index to errors returned from `evaluate_batch`, and serialize it in `ExecutionError`.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: src/calculator.rs:432
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
fu050409
approved these changes
Aug 29, 2026
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.
Summary
Typed success results remain part of the later result/API milestone; this PR keeps existing success payloads compatible.
Validation
Closes #12
Summary by Sourcery
Expose stable RFC-0003 structured failures across the Rust, Python, and CLI interfaces without breaking existing ValueError-based callers.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: