grafana/k6 · error
the body is null so we can't transform it to HTML - this lik
Error message
the body is null so we can't transform it to HTML - this likely was because of a request error getting the response
What it means
Response.HTML() was called on a response whose Body is nil. The body is null when the request errored before a body could be read (network failure, timeout, or a throw on status), so there is nothing to parse into an html.Selection. Also surfaces indirectly via SubmitForm/ClickLink, which call HTML() internally.
Source
Thrown at js/modules/k6/http/response.go:44
validatedJSON bool
}
type jsonError struct {
line int
character int
err error
}
func (j jsonError) Error() string {
errMessage := "cannot parse json due to an error at line"
return fmt.Sprintf("%s %d, character %d , error: %v", errMessage, j.line, j.character, j.err)
}
// HTML returns the body as an html.Selection
func (res *Response) HTML(selector ...string) html.Selection {
rt := res.client.moduleInstance.vu.Runtime()
if res.Body == nil {
err := fmt.Errorf("the body is null so we can't transform it to HTML" +
" - this likely was because of a request error getting the response")
common.Throw(rt, err)
}
body, err := common.ToString(res.Body)
if err != nil {
common.Throw(rt, err)
}
sel, err := html.ParseHTML(rt, body)
if err != nil {
common.Throw(rt, err)
}
sel.URL = res.URL
if len(selector) > 0 {
sel = sel.Find(selector[0])
}
return selView on GitHub (pinned to 01ffac6f24)
Solutions
- Check res.error / res.status or res.Body != null before calling res.html()
- Fix the underlying request error (URL, timeout, connectivity) so a real body is returned
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at js/modules/k6/http/response.go:44 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/d29934e0abc6c8c4.
Report an issue: GitHub.