minor fixes

This commit is contained in:
Kujtim Hoxha
2025-04-15 11:58:01 +02:00
parent f6be348bf7
commit 1cdd24fbc7
6 changed files with 49 additions and 27 deletions

View File

@@ -4,6 +4,8 @@ import (
"context"
"errors"
"fmt"
"os"
"runtime/debug"
"strings"
"sync"
@@ -88,6 +90,21 @@ func (a *agent) Generate(ctx context.Context, sessionID string, content string)
defer func() {
if r := recover(); r != nil {
logging.ErrorPersist(fmt.Sprintf("Panic in Generate: %v", r))
// dump stack trace into a file
file, err := os.Create("panic.log")
if err != nil {
logging.ErrorPersist(fmt.Sprintf("Failed to create panic log: %v", err))
return
}
defer file.Close()
stackTrace := debug.Stack()
if _, err := file.Write(stackTrace); err != nil {
logging.ErrorPersist(fmt.Sprintf("Failed to write panic log: %v", err))
}
}
}()
defer a.activeRequests.Delete(sessionID)