mirror of
https://github.com/hibiken/asynq.git
synced 2025-10-22 22:06:12 +08:00
error panic handling
This commit is contained in:
@@ -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
|
||||
*************************************************/
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user