2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-10-22 09:56:12 +08:00

error panic handling

This commit is contained in:
linhbkhn95
2022-09-21 09:26:51 +07:00
parent d0209d9273
commit 821541215c
7 changed files with 90 additions and 36 deletions

View File

@@ -256,6 +256,21 @@ func IsRedisCommandError(err error) bool {
return As(err, &target)
}
// PanicError defines an error when occurred a panic error.
type PanicError struct {
ErrMsg string
}
func (e *PanicError) Error() string {
return fmt.Sprintf("panic error cause by: %s", e.ErrMsg)
}
// IsPanicError reports whether any error in err's chain is of type PanicError.
func IsPanicError(err error) bool {
var target *PanicError
return As(err, &target)
}
/*************************************************
Standard Library errors package functions
*************************************************/

View File

@@ -131,6 +131,12 @@ func TestErrorPredicates(t *testing.T) {
err: E(Op("rdb.ArchiveTask"), NotFound, &QueueNotFoundError{Queue: "default"}),
want: true,
},
{
desc: "IsPanicError should detect presence of PanicError in err's chain",
fn: IsPanicError,
err: E(Op("unknown"), Unknown, &PanicError{ErrMsg: "Something went wrong"}),
want: true,
},
}
for _, tc := range tests {