{"record":{"id":"bbc8126d0a54de95","repo":"grafana/k6","slug":"the-built-in-check-does-not-support-async-functi","errorCode":null,"errorMessage":"the built-in check() does not support async functions as arguments. Use the JavaScript utils library as a replacement. Refer to https://grafana.com/docs/k6/latest/javascript-api/jslib/utils/check/ for more info","messagePattern":"the built-in check\\(\\) does not support async functions as arguments\\. Use the JavaScript utils library as a replacement\\. Refer to https://grafana\\.com/docs/k6/latest/javascript-api/jslib/utils/check/ for more info","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/k6.go","lineNumber":182,"sourceCode":"\t\t}\n\t}\n\n\tsucc := true\n\tvar exc error\n\tobj := checks.ToObject(rt)\n\tfor _, name := range obj.Keys() {\n\t\tif strings.Contains(name, lib.GroupSeparator) {\n\t\t\treturn false, lib.ErrNameContainsGroupSeparator\n\t\t}\n\t\tval := obj.Get(name)\n\n\t\ttags := commonTagsAndMeta.Tags\n\t\tif state.Options.SystemTags.Has(metrics.TagCheck) {\n\t\t\ttags = tags.With(\"check\", name)\n\t\t}\n\n\t\tif common.IsAsyncFunction(rt, val) {\n\t\t\treturn false, errors.New(\"the built-in check() does not support async functions as arguments. \" +\n\t\t\t\t\"Use the JavaScript utils library as a replacement. \" +\n\t\t\t\t\"Refer to https://grafana.com/docs/k6/latest/javascript-api/jslib/utils/check/ for more info\")\n\t\t}\n\n\t\t// Resolve callables into values.\n\t\tfn, ok := sobek.AssertFunction(val)\n\t\tif ok {\n\t\t\ttmpVal, err := fn(sobek.Undefined(), arg0)\n\t\t\tval = tmpVal\n\t\t\tif err != nil {\n\t\t\t\tval = rt.ToValue(false)\n\t\t\t\texc = err\n\t\t\t}\n\t\t}\n\t\tbooleanVal := val.ToBoolean()\n\t\tif !booleanVal {\n\t\t\t// A single failure makes the return value false.\n\t\t\tsucc = false","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/k6.go#L164-L200","documentation":"While iterating the checks object, k6 rejects values that are async functions (internal/js/modules/k6/k6.go:180). Check callbacks must return their boolean synchronously so the check metric can be tagged and emitted immediately; an async callback returns a promise whose result would arrive after the metric was recorded. The error message directs you to the jslib/k6 utils check replacement, which supports async check functions.","triggerScenarios":"`check(res, { 'ok': async (r) => { ... return r.status === 200 } })` — any check value defined as an async function or async arrow.","commonSituations":"Migrating from Playwright/Puppeteer-style scripts where async predicates are normal; wrapping checks around async helper calls; refactoring http_async or browser-based scripts into check bodies.","solutions":["Use jslib.k6.io's utils check: `import check from 'https://jslib.k6.io/k6-utils/1.5.0/check'` which supports async check functions","Make the check callback synchronous: perform awaits before check() and assert on the resolved value","Move async assertions out of check and record results with a custom metric or k6.check on precomputed booleans"],"exampleFix":"// before\ncheck(res, { 'payload ok': async (r) => (await r.json()).code === 0 });\n\n// after\nimport { check } from 'https://jslib.k6.io/k6-utils/1.5.0/check';\ncheck(res, { 'payload ok': async (r) => (await r.json()).code === 0 });","handlingStrategy":"type-guard","validationCode":"const AsyncFunction = (async () => {}).constructor;\nconst hasAsyncCheck = Object.values(checks).some((v) => v instanceof AsyncFunction);\nif (hasAsyncCheck) { throw new TypeError('use jslib/k6-utils check for async check functions'); }","typeGuard":"const containsAsyncCheck = (checks) =>\n  Object.values(checks).some((v) => v instanceof (async () => {}).constructor);","tryCatchPattern":"try {\n  check(res, checks);\n} catch (e) {\n  if (String(e.message).includes('does not support async functions')) {\n    throw new Error('replace k6/check with https://jslib.k6.io/k6-utils check for async assertions');\n  }\n  throw e;\n}","preventionTips":["Import check from jslib.k6.io k6-utils when any assertion is async","Await async data before check() and assert synchronously on the resolved values","Keep check bodies one-line boolean expressions over precomputed values"],"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"}