Skip to content

fix: #98 | Enhance the Try conditional recover and onFailure methods to use the predicate based methods#101

Merged
ShivamNagpal merged 1 commit intodevelopfrom
98-try-enhancements
Nov 13, 2025
Merged

fix: #98 | Enhance the Try conditional recover and onFailure methods to use the predicate based methods#101
ShivamNagpal merged 1 commit intodevelopfrom
98-try-enhancements

Conversation

@ShivamNagpal
Copy link
Copy Markdown
Contributor

@ShivamNagpal ShivamNagpal commented Nov 13, 2025

closes #98

Summary by CodeRabbit

Release Notes

  • New Features
    • Added recover methods supporting predicate-based exception matching for flexible conditional recovery.
    • Added onFailure callback methods supporting predicate-based exception matching for selective error processing.
    • New method overloads available as preview features providing enhanced control over failure handling and recovery scenarios.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 13, 2025

Walkthrough

Refactored Try exception recovery logic to support predicate-based filtering. Added new recover and onFailure methods accepting Predicate conditions, with existing exception-type variants delegating to predicate-based implementations. Updated compose behavior to route through failureMapper when Try is in failure state. Added @Preview annotations to varargs overloads and imported Predicate and Preview support.

Changes

Cohort / File(s) Summary
Predicate-Based Recovery Refactoring
src/main/java/org/zeplinko/commons/lang/ext/core/Try.java
Added foundational recover(Predicate, Function) and onFailure(Predicate, Consumer) methods; refactored recover(Class, Function) and onFailure(Class, Consumer) to delegate to predicate variants; marked recover(Function, Class...) and onFailure(Function/Consumer, Class...) varargs overloads with @Preview; updated compose to apply failureMapper when Try is failure; added Predicate and Preview imports.
Recovery Behavior Tests
src/test/java/org/zeplinko/commons/lang/ext/core/TryTest.java
Added comprehensive test coverage for predicate-based recover and onFailure, including null-safety checks, predicate matching/non-matching scenarios, and varargs form behavior; adjusted existing assertions for delegation patterns.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Try
    participant Predicate
    participant Mapper
    
    User->>Try: recover(predicate, mapper)
    alt Exception exists
        Try->>Predicate: test(exception)
        alt Predicate matches
            Predicate-->>Try: true
            Try->>Mapper: apply(exception)
            Mapper-->>Try: Try<T> (recovered)
            Try-->>User: Success path
        else Predicate does not match
            Predicate-->>Try: false
            Try-->>User: Failure path (unchanged)
        end
    else No exception
        Try-->>User: Success path (direct)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Key focus areas:
    • compose method behavioral change: now routes through failureMapper on failure instead of success path—verify this aligns with intended semantics
    • Predicate-based delegation chains in recover and onFailure overloads—trace execution paths to ensure correct branching
    • Null parameter handling in predicate and mapper arguments across new and refactored methods
    • @Preview annotation placement on varargs variants and implications for API stability
    • Parameter rename from failureMapper to mapper in recover(Class, Function) overload—check for consistency

Possibly related PRs

Poem

🐰 With predicates as guides so fine,
We test each exception in line,
No casting chaos, no messy fray—
Try recovers the clever way!
✨ Exception handling—refined at last!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 39.29% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly references issue #98 and describes the main change: enhancing Try's conditional recovery and onFailure methods to use predicate-based approaches.
Linked Issues check ✅ Passed The PR implements predicate-based recovery methods alongside type-specific overloads and varargs forms, directly addressing issue #98's requirement to eliminate verbose instanceof checks in exception recovery.
Out of Scope Changes check ✅ Passed All changes are focused on enhancing Try's recovery and onFailure methods as specified in issue #98; no unrelated modifications were introduced.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 98-try-enhancements

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ShivamNagpal ShivamNagpal changed the title fix: #98 | Enhance the Try conditional recover and onFailure methods … fix: #98 | Enhance the Try conditional recover and onFailure methods to use the predicate based methods Nov 13, 2025
@ShivamNagpal
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 13, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6f90f4 and d586ca4.

📒 Files selected for processing (2)
  • src/main/java/org/zeplinko/commons/lang/ext/core/Try.java (10 hunks)
  • src/test/java/org/zeplinko/commons/lang/ext/core/TryTest.java (4 hunks)

Comment thread src/main/java/org/zeplinko/commons/lang/ext/core/Try.java
@ShivamNagpal ShivamNagpal marked this pull request as ready for review November 13, 2025 09:40
Copy link
Copy Markdown
Contributor

@a-anand-91119 a-anand-91119 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One one concern, which is the same raised by code rabbit

@ShivamNagpal
Copy link
Copy Markdown
Contributor Author

@a-anand-91119 It will be fixed in the next version.

@ShivamNagpal ShivamNagpal merged commit 38087a1 into develop Nov 13, 2025
3 checks passed
@ShivamNagpal ShivamNagpal deleted the 98-try-enhancements branch November 13, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability for Try to recover from specific exceptions without having to write instance of check everytime.

2 participants