better recovery in unexpected situations

This commit is contained in:
Adam Majer 2025-02-24 13:11:54 +01:00
parent 4014747712
commit fffdce2c58
2 changed files with 15 additions and 1 deletions

View File

@ -178,7 +178,10 @@ func connectToRabbitMQ(log *log.Logger, server url.URL, topics []string) chan Ra
func ProcessEvent(f RequestProcessor, request *Request) { func ProcessEvent(f RequestProcessor, request *Request) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
log.Println(r) log.Println("panic caught")
if err, ok := r.(error); !ok {
log.Println(err)
}
log.Println(string(debug.Stack())) log.Println(string(debug.Stack()))
} }
}() }()

View File

@ -6,6 +6,7 @@ import (
"log" "log"
"math/rand" "math/rand"
"path" "path"
"runtime/debug"
"strings" "strings"
"time" "time"
@ -44,6 +45,16 @@ func CreateDefaultStateChecker(checkOnStart bool, processor *RequestProcessor, g
} }
func (s *DefaultStateChecker) VerifyProjectState(org string, configs []*common.AutogitConfig, idx int) error { func (s *DefaultStateChecker) VerifyProjectState(org string, configs []*common.AutogitConfig, idx int) error {
defer func() {
if r := recover(); r != nil {
log.Println("panic caught")
if err, ok := r.(error); !ok {
log.Println(err)
}
log.Println(string(debug.Stack()))
}
}()
git, err := s.git.CreateGitHandler(GitAuthor, GitEmail, AppName) git, err := s.git.CreateGitHandler(GitAuthor, GitEmail, AppName)
if err != nil { if err != nil {
return fmt.Errorf("Cannot create git handler: %w", err) return fmt.Errorf("Cannot create git handler: %w", err)