PanicHandler handles panic recovery and logging. It can be called directly with recover() without checking for nil first. Example usage: defer func() { util.PanicHandler("operation name", recover()) }()
(debugStr string, recoverVal any)
| 23 | // util.PanicHandler("operation name", recover()) |
| 24 | // }() |
| 25 | func PanicHandler(debugStr string, recoverVal any) error { |
| 26 | if recoverVal == nil { |
| 27 | return nil |
| 28 | } |
| 29 | log.Printf("[panic] in %s: %v\n", debugStr, recoverVal) |
| 30 | debug.PrintStack() |
| 31 | if err, ok := recoverVal.(error); ok { |
| 32 | return fmt.Errorf("panic in %s: %w", debugStr, err) |
| 33 | } |
| 34 | return fmt.Errorf("panic in %s: %v", debugStr, recoverVal) |
| 35 | } |
| 36 | |
| 37 | func GetHomeDir() string { |
| 38 | homeVar, err := os.UserHomeDir() |
no outgoing calls
no test coverage detected