grafana/k6 · error

unknown request body type %T

Error message

unknown request body type %T

What it means

parseRequest's type switch on the request body fell through to the default branch: the supplied body is none of string, []byte, ArrayBuffer, object (form data) or exported object map. The actual Go type is named.

Source

Thrown at js/modules/k6/http/request.go:305

			newData := map[string]any{}
			for k, v := range data {
				newData[k] = v.Export()
			}
			if err := handleObjectBody(newData); err != nil {
				return nil, err
			}
		case sobek.ArrayBuffer:
			result.Body = bytes.NewBuffer(data.Bytes())
		case map[string]any:
			if err := handleObjectBody(data); err != nil {
				return nil, err
			}
		case string:
			result.Body = bytes.NewBufferString(data)
		case []byte:
			result.Body = bytes.NewBuffer(data)
		default:
			return nil, fmt.Errorf("unknown request body type %T", body)
		}
	}

	result.Req.Header.Set("User-Agent", state.Options.UserAgent.String)

	if state.CookieJar != nil {
		result.ActiveJar = state.CookieJar
	}

	// TODO: ditch sobek.Value, reflections and Object and use a simple go map and type assertions?
	//nolint: nestif
	if !common.IsNullish(params) {
		params := params.ToObject(rt)
		for _, k := range params.Keys() {
			switch k {
			case "cookies":
				cookiesV := params.Get(k)
				if common.IsNullish(cookiesV) {

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Use a string, object (form-encoded), ArrayBuffer or binary data as the request body
  2. Convert numbers/other types to a string before passing them as data
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at js/modules/k6/http/request.go:305 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/bc378d0d61cb25c5. Report an issue: GitHub.