-
Notifications
You must be signed in to change notification settings - Fork 0
panic: introduce Catch() shortcut for Catcher.Do() #77
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
Conversation
Signed-off-by: Alejandro Mery <amery@apptly.co>
WalkthroughThe pull request introduces updates to the Changes
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Here's the code health analysis summary for commits Analysis Summary
|
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
🧹 Outside diff range and nitpick comments (2)
panic.go (1)
75-81: LGTM! Consider an optimization for high-frequency use cases.The new
Catchfunction is well-implemented and aligns perfectly with the PR objectives. It provides a clean and straightforward shortcut forCatcher.Do(), simplifying error handling in the context of panics.The function is concise, easy to understand, and has clear documentation. It correctly handles both organic errors and recovered panics, making it a valuable addition to the package.
For high-frequency use cases, consider providing an additional function that reuses a
Catcherinstance to avoid repeated allocations. For example:var globalCatcher Catcher // CatchWithReuse uses a global [Catcher] to safely call a function and // return the organic error or the [Recovered] [PanicError]. func CatchWithReuse(fn func() error) error { return globalCatcher.Do(fn) }This optimization could be beneficial in scenarios where
Catchis called frequently, and the slight performance improvement from reusing theCatcherinstance becomes significant.README.md (1)
95-97: LGTM! Consider adding a code example.The introduction of
Catch()is well-documented and aligns with the PR objectives. The description clearly explains its functionality and relationship withPanicErrorandCatcher.To further improve the documentation, consider adding a simple code example demonstrating the usage of
Catch(). This would help users quickly understand how to implement it in their code.
karasz
left a 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.
LGTM
Summary by CodeRabbit
New Features
Catchfunction for simplified error handling during function execution.Documentation