Skip to content

Commit

Permalink
update recommendation for async check
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbespalov committed Nov 5, 2024
1 parent 7e3f67e commit 1d6d66e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions js/modules/k6/k6.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package k6

import (
"errors"
"fmt"
"math/rand"
"strings"
"time"
Expand All @@ -24,9 +23,6 @@ var (
ErrCheckInInitContext = common.NewInitContextError("Using check() in the init context is not supported")
)

const asyncFunctionNotSupportedMsg = "%s() does not support async functions as arguments, " +
"please see https://grafana.com/docs/k6/latest/javascript-api/k6/group/#working-with-async-functions for more info"

type (
// RootModule is the global module instance that will create module
// instances for each VU.
Expand Down Expand Up @@ -104,7 +100,8 @@ func (mi *K6) Group(name string, val sobek.Value) (sobek.Value, error) {
return nil, errors.New("group() requires a callback as a second argument")
}
if common.IsAsyncFunction(mi.vu.Runtime(), val) {
return sobek.Undefined(), fmt.Errorf(asyncFunctionNotSupportedMsg, "group")
return sobek.Undefined(), errors.New("group() does not support async functions as arguments, " +
"please see https://grafana.com/docs/k6/latest/javascript-api/k6/group/#working-with-async-functions for more info")
}
oldGroupName, _ := state.Tags.GetCurrentValues().Tags.Get(metrics.TagGroup.String())
// TODO: what are we doing if group is not tagged
Expand Down Expand Up @@ -182,7 +179,9 @@ func (mi *K6) Check(arg0, checks sobek.Value, extras ...sobek.Value) (bool, erro
}

if common.IsAsyncFunction(rt, val) {
return false, fmt.Errorf(asyncFunctionNotSupportedMsg, "check")
return false, errors.New("built-in check() does not support async functions as arguments, " +
"please switch to JavaScript replacement, see " +
"https://grafana.com/docs/k6/latest/javascript-api/jslib/utils/check/ for more info")
}

// Resolve callables into values.
Expand Down

0 comments on commit 1d6d66e

Please sign in to comment.