grafana/k6 · error

no arguments

Error message

no arguments

What it means

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'.

Source

Thrown at js/modules/k6/http/response_callback.go:45

		return true
	}

	for _, v := range e.minmax {
		if v[0] <= status && status <= v[1] {
			return true
		}
	}
	return false
}

// expectedStatuses returns expectedStatuses object based on the provided arguments.
// The arguments must be either integers or object of `{min: <integer>, max: <integer>}`
// kind. The "integer"ness is checked by the Number.isInteger.
func (mi *ModuleInstance) expectedStatuses(args ...sobek.Value) *expectedStatuses {
	rt := mi.vu.Runtime()

	if len(args) == 0 {
		common.Throw(rt, errors.New("no arguments"))
	}
	var result expectedStatuses

	jsIsInt, _ := sobek.AssertFunction(rt.GlobalObject().Get("Number").ToObject(rt).Get("isInteger"))
	isInt := func(a sobek.Value) bool {
		v, err := jsIsInt(sobek.Undefined(), a)
		return err == nil && v.ToBoolean()
	}

	errMsg := "argument number %d to expectedStatuses was neither an integer nor an object like {min:100, max:329}"
	for i, arg := range args {
		o := arg.ToObject(rt)
		if o == nil {
			common.Throw(rt, fmt.Errorf(errMsg, i+1))
		}

		if isInt(arg) {
			result.exact = append(result.exact, int(o.ToInteger()))

View on GitHub (pinned to 93accf6570)

Solutions

  1. Pass at least one status: http.expectedStatuses(200)
  2. Or a range object: http.expectedStatuses({ min: 200, max: 399 })
  3. When building args dynamically, guard: if (statuses.length === 0) statuses = [200]

Example fix

// before
http.setResponseCallback(http.expectedStatuses());

// after
http.setResponseCallback(http.expectedStatuses({ min: 200, max: 399 }));
Defensive patterns

Strategy: validation

Validate before calling

const args = statuses.length ? statuses : [{ min: 200, max: 399 }];
http.setResponseCallback(http.expectedStatuses(...args));

Prevention

When it happens

Trigger: http.setResponseCallback(http.expectedStatuses()) with no arguments, e.g. when building the argument list dynamically and it ends up empty.

Common situations: 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.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/2d28363d625206cd. Report an issue: GitHub.