mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-10-19 04:24:05 +02:00
fixed unhandled panic and wrapped all internal goroutines
This commit is contained in:
1 parent
09044ef7a3
commit
f1618ee59b
13 files changed
+85
-37
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package routine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"runtime"
|
||||
"sync"
|
||||
@@ -33,3 +34,17 @@ func FireAndForget(f func(), wg ...*sync.WaitGroup) {
|
||||
f()
|
||||
}()
|
||||
}
|
||||
|
||||
// SafeWrap wraps the provided function with auto panic recover handling
|
||||
// and returns any eventual panic as regular error.
|
||||
func SafeWrap(f func() error) func() error {
|
||||
return func() (err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = fmt.Errorf("[SafeWrap] recovered from panic: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
return f()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user