mirror of
https://github.com/hibiken/asynq.git
synced 2025-09-17 20:30:06 +08:00
Compare commits
2 Commits
v0.25.1
...
sohail/cha
Author | SHA1 | Date | |
---|---|---|---|
![]() |
92973d6add | ||
![]() |
4c5202ee13 |
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- `IsPanicError` function is added to support catching of panic errors when processing tasks (PR: https://github.com/hibiken/asynq/pull/491)
|
||||||
|
|
||||||
## [0.24.1] - 2023-05-01
|
## [0.24.1] - 2023-05-01
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
10
processor.go
10
processor.go
@@ -415,21 +415,19 @@ func (p *processor) queues() []string {
|
|||||||
func (p *processor) perform(ctx context.Context, task *Task) (err error) {
|
func (p *processor) perform(ctx context.Context, task *Task) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if x := recover(); x != nil {
|
if x := recover(); x != nil {
|
||||||
errMsg := string(debug.Stack())
|
p.logger.Errorf("recovering from panic. See the stack trace below for details:\n%s", string(debug.Stack()))
|
||||||
|
|
||||||
p.logger.Errorf("recovering from panic. See the stack trace below for details:\n%s", errMsg)
|
|
||||||
_, file, line, ok := runtime.Caller(1) // skip the first frame (panic itself)
|
_, file, line, ok := runtime.Caller(1) // skip the first frame (panic itself)
|
||||||
if ok && strings.Contains(file, "runtime/") {
|
if ok && strings.Contains(file, "runtime/") {
|
||||||
// The panic came from the runtime, most likely due to incorrect
|
// The panic came from the runtime, most likely due to incorrect
|
||||||
// map/slice usage. The parent frame should have the real trigger.
|
// map/slice usage. The parent frame should have the real trigger.
|
||||||
_, file, line, ok = runtime.Caller(2)
|
_, file, line, ok = runtime.Caller(2)
|
||||||
}
|
}
|
||||||
|
var errMsg string
|
||||||
// Include the file and line number info in the error, if runtime.Caller returned ok.
|
// Include the file and line number info in the error, if runtime.Caller returned ok.
|
||||||
if ok {
|
if ok {
|
||||||
err = fmt.Errorf("panic [%s:%d]: %v", file, line, x)
|
errMsg = fmt.Sprintf("panic [%s:%d]: %v", file, line, x)
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("panic: %v", x)
|
errMsg = fmt.Sprintf("panic: %v", x)
|
||||||
}
|
}
|
||||||
err = &errors.PanicError{
|
err = &errors.PanicError{
|
||||||
ErrMsg: errMsg,
|
ErrMsg: errMsg,
|
||||||
|
Reference in New Issue
Block a user