Skip to content

Commit

Permalink
Used zap's stacktrace capturing in 'recover'.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickeskov committed Jan 3, 2024
1 parent 7a5ae6e commit 517803a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
9 changes: 2 additions & 7 deletions cmd/bots/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"log"
"os"
"os/signal"
"runtime/debug"
"syscall"
"time"

Expand Down Expand Up @@ -80,13 +79,9 @@ func (c *discordBotConfig) validate(zap *zap.Logger) error {
func handleRecover(logger *zap.Logger) {
if r := recover(); r != nil {
if rErr, ok := r.(error); ok {
logger.Fatal("Panic has been occurred", zap.ByteString("stacktrace", debug.Stack()),
zap.Error(rErr),
)
logger.Fatal("Panic has been occurred", zap.Stack("stacktrace"), zap.Error(rErr))
} else {
logger.Fatal("Panic has been occurred", zap.ByteString("stacktrace", debug.Stack()),
zap.Any("recovered-data", r),
)
logger.Fatal("Panic has been occurred", zap.Stack("stacktrace"), zap.Any("recovered-data", r))
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions cmd/bots/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"log"
"os"
"os/signal"
"runtime/debug"
"syscall"
"time"

Expand Down Expand Up @@ -101,13 +100,9 @@ func (c *telegramBotConfig) validate(logger *zap.Logger) error {
func handleRecover(logger *zap.Logger) {
if r := recover(); r != nil {
if rErr, ok := r.(error); ok {
logger.Fatal("Panic has been occurred", zap.ByteString("stacktrace", debug.Stack()),
zap.Error(rErr),
)
logger.Fatal("Panic has been occurred", zap.Stack("stacktrace"), zap.Error(rErr))
} else {
logger.Fatal("Panic has been occurred", zap.ByteString("stacktrace", debug.Stack()),
zap.Any("recovered-data", r),
)
logger.Fatal("Panic has been occurred", zap.Stack("stacktrace"), zap.Any("recovered-data", r))
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions cmd/nodemon/nodemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"log"
"os"
"os/signal"
"runtime/debug"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -184,13 +183,9 @@ func (c *nodemonConfig) runTelegramPairServer() bool { return c.nanomsgPairTeleg
func handleRecover(logger *zap.Logger) {
if r := recover(); r != nil {
if rErr, ok := r.(error); ok {
logger.Fatal("Panic has been occurred", zap.ByteString("stacktrace", debug.Stack()),
zap.Error(rErr),
)
logger.Fatal("Panic has been occurred", zap.Stack("stacktrace"), zap.Error(rErr))
} else {
logger.Fatal("Panic has been occurred", zap.ByteString("stacktrace", debug.Stack()),
zap.Any("recovered-data", r),
)
logger.Fatal("Panic has been occurred", zap.Stack("stacktrace"), zap.Any("recovered-data", r))
}
}
}
Expand Down

0 comments on commit 517803a

Please sign in to comment.