-
Notifications
You must be signed in to change notification settings - Fork 42
fix: replace unwrap() with proper error handling in regex compilation #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: replace unwrap() with proper error handling in regex compilation #108
Conversation
Replaced all .unwrap() calls in regex compilation and JSON parsing with proper error handling using ? operator and custom error types. Added JsonParseError variant to handle JSON parsing failures gracefully. This prevents potential panics and improves error reporting for invalid regex patterns or malformed JSON configurations.
WalkthroughError handling improvements for JSON parsing in the extract_substrs module. Replaced unwrap-based parsing with explicit error handling, introducing a new JsonParseError variant to the ExtractSubstrssError enum, and propagating JSON failures through the normal error channel across ten extraction functions. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes The changes are straightforward and follow a consistent pattern: replacing panics with proper error handling across multiple function calls. The modifications are localized to a single file with repetitive, homogeneous updates that facilitate predictable review. Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/apis/src/extract_substrs.rs (1)
65-66: Fix typo in comment and consider rewording.Minor typo: "seperate" should be "separate".
Additionally, consider updating the comment to reflect that while failure is unlikely after validating individual parts, using
?provides defensive error handling for edge cases that might arise from the regex transformations.Apply this diff to fix the typo:
- // This should be impossible to fail, since we tested the seperate regex parts before. + // This should be impossible to fail, since we tested the separate regex parts before.Or update the comment to be more accurate:
- // This should be impossible to fail, since we tested the seperate regex parts before. + // Should not fail since individual parts were validated, but handle error defensively.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/apis/src/extract_substrs.rs(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/apis/src/extract_substrs.rs (1)
packages/apis/src/wasm.rs (1)
serde_json(173-173)
🔇 Additional comments (3)
packages/apis/src/extract_substrs.rs (3)
39-40: LGTM! Well-defined error variant.The new
JsonParseErrorvariant properly integrates with the existing error enum and will provide clear error messages when JSON parsing fails.
59-62: Good cleanup: removing unused enumeration.The loop no longer needs the index since it's only building the regex string. This simplification improves readability.
108-110: Excellent: consistent error handling across all extraction functions.All ten functions now properly handle JSON parsing errors using a consistent pattern. The error mapping preserves the original error details via
to_string(), and the?operator correctly propagates failures through the call stack.Also applies to: 117-119, 133-135, 142-144, 149-151, 156-158, 165-167, 174-176, 183-185, 192-194
Replaced all .unwrap() calls in regex compilation and JSON parsing with proper error handling using ? operator and custom error types. Added JsonParseError variant to handle JSON parsing failures gracefully. This prevents potential panics and improves error reporting for invalid regex patterns or malformed JSON configurations.
Summary by CodeRabbit