grafana/k6 · error
group() does not support async functions as arguments, pleas
Error message
group() does not support async functions as arguments, please see https://grafana.com/docs/k6/latest/javascript-api/k6/group/ for more info
What it means
k6's execution model does not support async lifecycle callbacks. `k6.group` explicitly rejects async functions (internal/js/modules/k6/k6.go:102) because the group scope tags would be popped before the awaited continuation runs, corrupting metric tagging. The error points to the k6 group docs for alternatives.
Source
Thrown at internal/js/modules/k6/k6.go:103
mi.vu.Runtime().SetRandSource(randSource)
}
// Group wraps a function call and executes it within the provided group name.
func (mi *K6) Group(name string, val sobek.Value) (sobek.Value, error) {
state := mi.vu.State()
if state == nil {
return nil, ErrGroupInInitContext
}
if common.IsNullish(val) {
return nil, errors.New("group() requires a callback as a second argument")
}
fn, ok := sobek.AssertFunction(val)
if !ok {
return nil, errors.New("group() requires a callback as a second argument")
}
if common.IsAsyncFunction(mi.vu.Runtime(), val) {
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/ for more info")
}
oldGroupName, _ := state.Tags.GetCurrentValues().Tags.Get(metrics.TagGroup.String())
// TODO: what are we doing if group is not tagged
newGroupName, err := lib.NewGroupPath(oldGroupName, name)
if err != nil {
return sobek.Undefined(), err
}
shouldUpdateTag := state.Options.SystemTags.Has(metrics.TagGroup)
if shouldUpdateTag {
state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) {
tagsAndMeta.SetSystemTagOrMeta(metrics.TagGroup, newGroupName)
})
}
defer func() {
if shouldUpdateTag {
state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) {View on GitHub (pinned to 93accf6570)
Solutions
- Convert the callback to a synchronous function: do the awaits before group, or chain .then() inside if it does not cross the group boundary
- Restructure so async work happens outside group() and group() only wraps synchronous assertions
- Keep using plain functions for group/check/callbacks — async is only supported for dedicated APIs in k6
Example fix
// before
k6.group('async-flow', async () => {
const res = await doAsyncRequest();
check(res, { ok: (r) => r.status === 200 });
});
// after
const res = doAsyncRequest(); // schedule/perform outside group
k6.group('async-flow', () => {
check(res, { ok: (r) => r.status === 200 });
}); Defensive patterns
Strategy: type-guard
Validate before calling
const AsyncFunction = (async () => {}).constructor;
if (fn instanceof AsyncFunction) { throw new TypeError('group() does not accept async functions'); } Type guard
const isAsyncFunction = (fn) => fn instanceof (async () => {}).constructor; Try / catch
try {
k6.group('phase', fn);
} catch (e) {
if (String(e.message).includes('does not support async functions')) throw new Error('rewrite the group callback as a synchronous function (see k6 group docs)');
throw e;
} Prevention
- Write group/check callbacks as plain synchronous functions
- Perform awaits before entering group and pass results in via closure
- Enable strict linting against async keywords in k6 callback positions
When it happens
Trigger: `k6.group('g', async () => { ... })` — an async function, an async arrow, or a function that returns a promise passed where the callback is expected (async detection is done on the function itself, so plain functions returning promises are not caught here).
Common situations: Writing modern async/await style scripts (e.g. with fetch or async httpx-style helpers) and wrapping them in group; converting working code to async during a refactor; k6 v0.36+ where async support grew for some APIs but not group.
Related errors
- the built-in check() does not support async functions as arg
- Uncaught (in promise) ${value}
- predicate function is not callable
- empty gRPC client
- not a gRPC client
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/73078652c0f0f92e.
Report an issue: GitHub.