{"record":{"id":"73078652c0f0f92e","repo":"grafana/k6","slug":"group-does-not-support-async-functions-as-argume","errorCode":null,"errorMessage":"group() does not support async functions as arguments, please see https://grafana.com/docs/k6/latest/javascript-api/k6/group/ for more info","messagePattern":"group\\(\\) does not support async functions as arguments, please see https://grafana\\.com/docs/k6/latest/javascript-api/k6/group/ for more info","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/k6.go","lineNumber":103,"sourceCode":"\tmi.vu.Runtime().SetRandSource(randSource)\n}\n\n// Group wraps a function call and executes it within the provided group name.\nfunc (mi *K6) Group(name string, val sobek.Value) (sobek.Value, error) {\n\tstate := mi.vu.State()\n\tif state == nil {\n\t\treturn nil, ErrGroupInInitContext\n\t}\n\n\tif common.IsNullish(val) {\n\t\treturn nil, errors.New(\"group() requires a callback as a second argument\")\n\t}\n\tfn, ok := sobek.AssertFunction(val)\n\tif !ok {\n\t\treturn nil, errors.New(\"group() requires a callback as a second argument\")\n\t}\n\tif common.IsAsyncFunction(mi.vu.Runtime(), val) {\n\t\treturn sobek.Undefined(), errors.New(\"group() does not support async functions as arguments, \" +\n\t\t\t\"please see https://grafana.com/docs/k6/latest/javascript-api/k6/group/ for more info\")\n\t}\n\toldGroupName, _ := state.Tags.GetCurrentValues().Tags.Get(metrics.TagGroup.String())\n\t// TODO: what are we doing if group is not tagged\n\tnewGroupName, err := lib.NewGroupPath(oldGroupName, name)\n\tif err != nil {\n\t\treturn sobek.Undefined(), err\n\t}\n\n\tshouldUpdateTag := state.Options.SystemTags.Has(metrics.TagGroup)\n\tif shouldUpdateTag {\n\t\tstate.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) {\n\t\t\ttagsAndMeta.SetSystemTagOrMeta(metrics.TagGroup, newGroupName)\n\t\t})\n\t}\n\tdefer func() {\n\t\tif shouldUpdateTag {\n\t\t\tstate.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) {","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/k6.go#L85-L121","documentation":"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.","triggerScenarios":"`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).","commonSituations":"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.","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"],"exampleFix":"// before\nk6.group('async-flow', async () => {\n  const res = await doAsyncRequest();\n  check(res, { ok: (r) => r.status === 200 });\n});\n\n// after\nconst res = doAsyncRequest(); // schedule/perform outside group\nk6.group('async-flow', () => {\n  check(res, { ok: (r) => r.status === 200 });\n});","handlingStrategy":"type-guard","validationCode":"const AsyncFunction = (async () => {}).constructor;\nif (fn instanceof AsyncFunction) { throw new TypeError('group() does not accept async functions'); }","typeGuard":"const isAsyncFunction = (fn) => fn instanceof (async () => {}).constructor;","tryCatchPattern":"try {\n  k6.group('phase', fn);\n} catch (e) {\n  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)');\n  throw e;\n}","preventionTips":["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"],"tags":["k6-api","async","javascript","api-misuse"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}