Skip to content

Commit

Permalink
correct msg panic error
Browse files Browse the repository at this point in the history
  • Loading branch information
linhbkhn95 committed Oct 8, 2023
1 parent 4edef08 commit e25d45e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,21 +412,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)

Check warning on line 427 in processor.go

View check run for this annotation

Codecov / codecov/patch

processor.go#L427

Added line #L427 was not covered by tests
}
err = &errors.PanicError{
ErrMsg: errMsg,
Expand Down

0 comments on commit e25d45e

Please sign in to comment.