Skip to content

Commit

Permalink
hide ugly deprecation message for panic recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Jul 12, 2022
1 parent 0a95ffc commit 294ed6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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

0 comments on commit 294ed6a

Please sign in to comment.