feat: don't panic#8
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a helper function, DontPanic, to recover from panics by capturing and adding contextual key-value pairs (operation, code, severity, and file information) into the error output while also updating the error message formatting throughout the package. Key changes include:
- Switching the key-value separator from “:” to “=” in error messages.
- Adding the new DontPanic function and associated tests to safely recover from panics.
- Refactoring caller information functions (getWithCaller → getCallerOp) and updating related logic in op.go and with.go.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| with_test.go | Updated tests to validate error messages with the new “=” formatting and caller info. |
| with.go | Replaced the deprecated caller function with getCallerOp and removed legacy code. |
| op.go | Introduced getCallerOp, consolidated duplicate functionality, and updated comments. |
| formatter_test.go | Revised expected error strings to match the new “=” separator format. |
| formatter.go | Updated output formatting in writeKV to use “=” instead of “:”. |
| example/main.go | Added sample usages of DontPanic demonstrating handling of both anonymous and named panics. |
| dont_panic_test.go | Added tests to confirm DontPanic correctly recovers from panics. |
| dont_panic.go | New file implementing DontPanic with generic support for panic-recovering functions. |
Adds a helper function to recover from panics and automatically adds relevant key-values, like operation, code, severity and file where the panic occurred. The `DontPanic` function will add and operation for the panicking function with file and line number. The key-value format was change to `key=value` instead of `key: value` for better readability.
5fb674e to
37c1fed
Compare
xico42
approved these changes
Jun 23, 2025
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.
Adds a helper function to recover from panics and automatically adds relevant key-values, like operation, code, severity and file where the panic occurred.
The
DontPanicfunction will add and operation for the panicking function with file and line number.The key-value format was change to
key=valueinstead ofkey: valuefor better readability.