From 174008843d44be66ae64e79c68824433f3b19268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BB=8Bnh=20=C4=90=E1=BB=A9c=20B=E1=BA=A3o=20Linh=28Ke?= =?UTF-8?q?vin=29?= Date: Mon, 6 May 2024 12:46:19 +0700 Subject: [PATCH] feat(*): correct panic error (#758) * error panic handling * updated CHANGELOG.md file * correct msg panic error (#5) * correct msg panic error --- processor.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/processor.go b/processor.go index 0ba9890..4c6471a 100644 --- a/processor.go +++ b/processor.go @@ -415,21 +415,19 @@ func (p *processor) queues() []string { func (p *processor) perform(ctx context.Context, task *Task) (err error) { defer func() { if x := recover(); x != nil { - errMsg := string(debug.Stack()) - - p.logger.Errorf("recovering from panic. See the stack trace below for details:\n%s", errMsg) + p.logger.Errorf("recovering from panic. See the stack trace below for details:\n%s", string(debug.Stack())) _, file, line, ok := runtime.Caller(1) // skip the first frame (panic itself) if ok && strings.Contains(file, "runtime/") { // The panic came from the runtime, most likely due to incorrect // map/slice usage. The parent frame should have the real trigger. _, file, line, ok = runtime.Caller(2) } - + var errMsg string // Include the file and line number info in the error, if runtime.Caller returned ok. if ok { - err = fmt.Errorf("panic [%s:%d]: %v", file, line, x) + errMsg = fmt.Sprintf("panic [%s:%d]: %v", file, line, x) } else { - err = fmt.Errorf("panic: %v", x) + errMsg = fmt.Sprintf("panic: %v", x) } err = &errors.PanicError{ ErrMsg: errMsg,