grafana/k6 · error

argument number %d to expectedStatuses was neither an intege

Error message

argument number %d to expectedStatuses was neither an integer nor an object like {min:100, max:329}

What it means

expectedStatuses received an argument that is neither an integer status code nor an object with min/max. The guard fires when arg.ToObject() yields nil or when the object lacks both min and max — e.g. http.expectedStatuses('200') or http.expectedStatuses({code: 200}).

Source

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

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()))
		} else {
			minValue := o.Get("min")
			maxValue := o.Get("max")
			if minValue == nil || maxValue == nil {
				common.Throw(rt, fmt.Errorf(errMsg, i+1))
			}
			if !isInt(minValue) || !isInt(maxValue) {
				common.Throw(rt, fmt.Errorf("both min and max need to be integers for argument number %d", i+1))
			}

			result.minmax = append(result.minmax, [2]int{int(minValue.ToInteger()), int(maxValue.ToInteger())})
		}
	}
	return &result

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Pass integers or ranges: http.expectedStatuses(200, 300-399) or http.expectedStatuses({min: 200, max: 399})
  2. Do not pass strings or objects without min/max properties
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at js/modules/k6/http/response_callback.go:59 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/6ea69245bcf50510. Report an issue: GitHub.