Skip to content

feat: don't panic#8

Merged
rjfonseca merged 1 commit into
mainfrom
feat/dont-panic
Jun 23, 2025
Merged

feat: don't panic#8
rjfonseca merged 1 commit into
mainfrom
feat/dont-panic

Conversation

@rjfonseca
Copy link
Copy Markdown
Member

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.

Copilot AI review requested due to automatic review settings June 23, 2025 13:32
@rjfonseca rjfonseca requested a review from xico42 as a code owner June 23, 2025 13:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread op.go Outdated
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.
@rjfonseca rjfonseca merged commit 28ca7bd into main Jun 23, 2025
3 checks passed
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.

3 participants