-
Notifications
You must be signed in to change notification settings - Fork 29
Closed
Labels
error-handlingRelated to error handling improvementsRelated to error handling improvementspriority-highCritical issues that should be addressed firstCritical issues that should be addressed firstrefactorCode refactoring without changing behaviorCode refactoring without changing behavior
Description
Issue #3: Reduce .unwrap() usage in model/option.rs
Title
refactor: Replace unwrap() calls with proper error handling in model/option.rs
Labels
refactorerror-handlingpriority-high
Description
The file src/model/option.rs contains 134 occurrences of .unwrap(). The Options struct is fundamental to the library and should handle errors gracefully.
Current State
- 134
.unwrap()calls in production code - Core option operations can panic
- Invalid option parameters cause crashes instead of errors
Target State
- Zero
.unwrap()calls in production code - All public methods return
Resultwhere failure is possible - Clear error messages for invalid parameters
Tasks
- Audit all
.unwrap()calls inmodel/option.rs - Replace with proper error handling using
OptionsError - Ensure all public methods return
Resultwhere failure is possible - Add validation for option parameters:
- Strike price > 0
- Underlying price > 0
- Volatility > 0
- Time to expiration >= 0
- Update documentation with error conditions
- Run
make lint-fixandmake pre-pushto verify
Acceptance Criteria
- No
.unwrap()calls remain in production code - All existing tests pass
- API documentation includes error conditions
- Invalid parameters produce clear error messages
- Option creation validates all inputs
Technical Notes
Validation Pattern
impl Options {
pub fn new(
strike: Positive,
underlying: Positive,
volatility: Positive,
// ...
) -> Result<Self, OptionsError> {
// Validation is handled by Positive type
// Additional business logic validation here
Ok(Self {
strike,
underlying,
volatility,
// ...
})
}
}Error Handling Pattern
// Before
let price = self.calculate_price().unwrap();
// After
let price = self.calculate_price()
.map_err(|e| OptionsError::PricingFailed(e.to_string()))?;Files to Update
src/model/option.rs(primary)src/error/options.rs(add error variants)- Related test files
Estimated Effort
Medium (4-6 hours)
Dependencies
None
Related Issues
- Issue Implementation of the Binomial Model for Option Pricing #1: Reduce unwrap() in chains/chain.rs
- Issue Feature/draw binomial tree #2: Reduce unwrap() in greeks/equations.rs
Metadata
Metadata
Assignees
Labels
error-handlingRelated to error handling improvementsRelated to error handling improvementspriority-highCritical issues that should be addressed firstCritical issues that should be addressed firstrefactorCode refactoring without changing behaviorCode refactoring without changing behavior