From d42a3b9c949d02125139e8f1b61977e22060472a Mon Sep 17 00:00:00 2001 From: leiyuan Date: Thu, 23 Jun 2022 12:42:58 +0800 Subject: [PATCH] deferDo method logic should not be wrapped by defer agin,thus results panic ignored and not do fail method --- dtmcli/dtmimp/utils.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/dtmcli/dtmimp/utils.go b/dtmcli/dtmimp/utils.go index 1e5607a..3127fbe 100644 --- a/dtmcli/dtmimp/utils.go +++ b/dtmcli/dtmimp/utils.go @@ -235,16 +235,14 @@ func RespAsErrorCompatible(resp *resty.Response) error { // DeferDo a common defer do used in dtmcli/dtmgrpc func DeferDo(rerr *error, success func() error, fail func() error) { - defer func() { - if x := recover(); x != nil { - _ = fail() - panic(x) - } else if *rerr != nil { - _ = fail() - } else { - *rerr = success() - } - }() + if x := recover(); x != nil { + _ = fail() + panic(x) + } else if *rerr != nil { + _ = fail() + } else { + *rerr = success() + } } // Escape solve CodeQL reported problem