Skip to content
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

hide ugly deprecation message for panic recovery #49

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ generated/
bin/*
gin-bin
.idea/
.vscode/
9 changes: 5 additions & 4 deletions internal/safe/safe.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@ func Run(fn func()) (err error) {

var warningOnce sync.Once

const warning = "WARNING! currently, genny recovers panic on the runner functions but the behavior will be dropped. please prepare your own recovery methods if you need them."
// see discussion on PR #47
const warning = "PANIC RECOVERED! currently, genny recovers panic on the runner functions but the behavior will be dropped. please prepare your own recovery."

// Run the function safely knowing that if it panics
// the panic will be caught and returned as an error
func RunE(fn func() error) (err error) {
warningOnce.Do(func() {
fmt.Fprintln(os.Stderr, warning)
})
defer func() {
if err != nil {
return
}
if ex := recover(); ex != nil {
warningOnce.Do(func() {
fmt.Fprintln(os.Stderr, warning)
})
if e, ok := ex.(error); ok {
err = e
return
Expand Down