Skip to content

Commit 9b85096

Browse files
committed
Fix anonymous function name detection
Signed-off-by: Tiago Scolari <[email protected]>
1 parent f4ba09f commit 9b85096

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

workflow/worker.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"log"
2222
"reflect"
23+
"regexp"
2324
"runtime"
2425
"strings"
2526

@@ -90,10 +91,15 @@ func getFunctionName(f interface{}) (string, error) {
9091
}
9192

9293
callSplit := strings.Split(runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name(), ".")
93-
9494
funcName := callSplit[len(callSplit)-1]
9595

96-
if funcName == "1" {
96+
const anonymousFunctionRegxp = "^func[0-9]+$"
97+
isAnonymousFunc, err := regexp.MatchString(anonymousFunctionRegxp, funcName)
98+
if err != nil {
99+
return "", fmt.Errorf("failed to match anonymous function regexp: %w", err)
100+
}
101+
102+
if isAnonymousFunc {
97103
return "", errors.New("anonymous function name")
98104
}
99105

0 commit comments

Comments
 (0)