mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-01-20 17:44:26 +00:00
Merge pull request #7 from bitechdev/copilot/sub-pr-5-again
Fix recover() not working in CatchPanic functions
This commit is contained in:
@@ -90,12 +90,12 @@ Panics are automatically captured when using the logger's panic handlers:
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
// Using CatchPanic
|
// Using CatchPanic
|
||||||
defer logger.CatchPanic("MyFunction")
|
defer logger.CatchPanic("MyFunction")()
|
||||||
|
|
||||||
// Using CatchPanicCallback
|
// Using CatchPanicCallback
|
||||||
defer logger.CatchPanicCallback("MyFunction", func(err any) {
|
defer logger.CatchPanicCallback("MyFunction", func(err any) {
|
||||||
// Custom cleanup
|
// Custom cleanup
|
||||||
})
|
})()
|
||||||
|
|
||||||
// Using HandlePanic
|
// Using HandlePanic
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|||||||
@@ -148,8 +148,11 @@ func Debug(template string, args ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CatchPanic - Handle panic
|
// CatchPanic - Handle panic
|
||||||
func CatchPanicCallback(location string, cb func(err any), args ...interface{}) {
|
// Returns a function that should be deferred to catch panics
|
||||||
|
// Example usage: defer CatchPanicCallback("MyFunction", func(err any) { /* cleanup */ })()
|
||||||
|
func CatchPanicCallback(location string, cb func(err any), args ...interface{}) func() {
|
||||||
ctx, _ := extractContext(args...)
|
ctx, _ := extractContext(args...)
|
||||||
|
return func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
callstack := debug.Stack()
|
callstack := debug.Stack()
|
||||||
|
|
||||||
@@ -172,11 +175,14 @@ func CatchPanicCallback(location string, cb func(err any), args ...interface{})
|
|||||||
cb(err)
|
cb(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CatchPanic - Handle panic
|
// CatchPanic - Handle panic
|
||||||
func CatchPanic(location string, args ...interface{}) {
|
// Returns a function that should be deferred to catch panics
|
||||||
CatchPanicCallback(location, nil, args...)
|
// Example usage: defer CatchPanic("MyFunction")()
|
||||||
|
func CatchPanic(location string, args ...interface{}) func() {
|
||||||
|
return CatchPanicCallback(location, nil, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandlePanic logs a panic and returns it as an error
|
// HandlePanic logs a panic and returns it as an error
|
||||||
|
|||||||
@@ -296,7 +296,7 @@ func setColSecValue(fieldsrc reflect.Value, colsec ColumnSecurity, fieldTypeName
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *SecurityList) ApplyColumnSecurity(records reflect.Value, modelType reflect.Type, pUserID int, pSchema, pTablename string) (reflect.Value, error) {
|
func (m *SecurityList) ApplyColumnSecurity(records reflect.Value, modelType reflect.Type, pUserID int, pSchema, pTablename string) (reflect.Value, error) {
|
||||||
defer logger.CatchPanic("ApplyColumnSecurity")
|
defer logger.CatchPanic("ApplyColumnSecurity")()
|
||||||
|
|
||||||
if m.ColumnSecurity == nil {
|
if m.ColumnSecurity == nil {
|
||||||
return records, fmt.Errorf("security not initialized")
|
return records, fmt.Errorf("security not initialized")
|
||||||
@@ -437,7 +437,7 @@ func (m *SecurityList) LoadRowSecurity(ctx context.Context, pUserID int, pSchema
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *SecurityList) GetRowSecurityTemplate(pUserID int, pSchema, pTablename string) (RowSecurity, error) {
|
func (m *SecurityList) GetRowSecurityTemplate(pUserID int, pSchema, pTablename string) (RowSecurity, error) {
|
||||||
defer logger.CatchPanic("GetRowSecurityTemplate")
|
defer logger.CatchPanic("GetRowSecurityTemplate")()
|
||||||
|
|
||||||
if m.RowSecurity == nil {
|
if m.RowSecurity == nil {
|
||||||
return RowSecurity{}, fmt.Errorf("security not initialized")
|
return RowSecurity{}, fmt.Errorf("security not initialized")
|
||||||
|
|||||||
Reference in New Issue
Block a user