More Panic Recovery for reflection on orm

This commit is contained in:
Hein
2025-11-20 15:20:21 +02:00
parent 311e50bfdd
commit 745564f2e7
4 changed files with 173 additions and 28 deletions

View File

@@ -103,3 +103,14 @@ func CatchPanicCallback(location string, cb func(err any)) {
func CatchPanic(location string) {
CatchPanicCallback(location, nil)
}
// RecoverPanic recovers from panics and returns an error
// Use this in deferred functions to convert panics into errors
func RecoverPanic(methodName string) error {
if r := recover(); r != nil {
stack := debug.Stack()
Error("Panic in %s: %v\nStack trace:\n%s", methodName, r, string(stack))
return fmt.Errorf("panic in %s: %v", methodName, r)
}
return nil
}