{"record":{"id":"2d28363d625206cd","repo":"grafana/k6","slug":"no-arguments","errorCode":null,"errorMessage":"no arguments","messagePattern":"no arguments","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"js/modules/k6/http/response_callback.go","lineNumber":45,"sourceCode":"\t\treturn true\n\t}\n\n\tfor _, v := range e.minmax {\n\t\tif v[0] <= status && status <= v[1] {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n// expectedStatuses returns expectedStatuses object based on the provided arguments.\n// The arguments must be either integers or object of `{min: <integer>, max: <integer>}`\n// kind. The \"integer\"ness is checked by the Number.isInteger.\nfunc (mi *ModuleInstance) expectedStatuses(args ...sobek.Value) *expectedStatuses {\n\trt := mi.vu.Runtime()\n\n\tif len(args) == 0 {\n\t\tcommon.Throw(rt, errors.New(\"no arguments\"))\n\t}\n\tvar result expectedStatuses\n\n\tjsIsInt, _ := sobek.AssertFunction(rt.GlobalObject().Get(\"Number\").ToObject(rt).Get(\"isInteger\"))\n\tisInt := func(a sobek.Value) bool {\n\t\tv, err := jsIsInt(sobek.Undefined(), a)\n\t\treturn err == nil && v.ToBoolean()\n\t}\n\n\terrMsg := \"argument number %d to expectedStatuses was neither an integer nor an object like {min:100, max:329}\"\n\tfor i, arg := range args {\n\t\to := arg.ToObject(rt)\n\t\tif o == nil {\n\t\t\tcommon.Throw(rt, fmt.Errorf(errMsg, i+1))\n\t\t}\n\n\t\tif isInt(arg) {\n\t\t\tresult.exact = append(result.exact, int(o.ToInteger()))","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/js/modules/k6/http/response_callback.go#L27-L63","documentation":"http.expectedStatuses() builds the match set for the response callback from its arguments (integers or {min, max} objects); calling it with zero arguments throws immediately via common.Throw. The resulting object is normally fed straight into http.setResponseCallback(), and an empty set would make every status 'unexpected'.","triggerScenarios":"http.setResponseCallback(http.expectedStatuses()) with no arguments, e.g. when building the argument list dynamically and it ends up empty.","commonSituations":"Dynamically computed status lists that turn out empty (filtered arrays, env-driven config); refactors that moved the statuses into a variable that is never spread; placeholder code left from scaffolding.","solutions":["Pass at least one status: http.expectedStatuses(200)","Or a range object: http.expectedStatuses({ min: 200, max: 399 })","When building args dynamically, guard: if (statuses.length === 0) statuses = [200]"],"exampleFix":"// before\nhttp.setResponseCallback(http.expectedStatuses());\n\n// after\nhttp.setResponseCallback(http.expectedStatuses({ min: 200, max: 399 }));","handlingStrategy":"validation","validationCode":"const args = statuses.length ? statuses : [{ min: 200, max: 399 }];\nhttp.setResponseCallback(http.expectedStatuses(...args));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass at least one status or range object","Guard dynamically built argument lists for emptiness","Prefer the { min, max } form to cover ranges explicitly"],"tags":["javascript","http","response-callback","statuses","validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}