{"record":{"id":"d29934e0abc6c8c4","repo":"grafana/k6","slug":"the-body-is-null-so-we-can-t-transform-it-to-html","errorCode":null,"errorMessage":"the body is null so we can't transform it to HTML - this likely was because of a request error getting the response","messagePattern":"the body is null so we can't transform it to HTML - this likely was because of a request error getting the response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"js/modules/k6/http/response.go","lineNumber":44,"sourceCode":"\tvalidatedJSON bool\n}\n\ntype jsonError struct {\n\tline      int\n\tcharacter int\n\terr       error\n}\n\nfunc (j jsonError) Error() string {\n\terrMessage := \"cannot parse json due to an error at line\"\n\treturn fmt.Sprintf(\"%s %d, character %d , error: %v\", errMessage, j.line, j.character, j.err)\n}\n\n// HTML returns the body as an html.Selection\nfunc (res *Response) HTML(selector ...string) html.Selection {\n\trt := res.client.moduleInstance.vu.Runtime()\n\tif res.Body == nil {\n\t\terr := fmt.Errorf(\"the body is null so we can't transform it to HTML\" +\n\t\t\t\" - this likely was because of a request error getting the response\")\n\t\tcommon.Throw(rt, err)\n\t}\n\n\tbody, err := common.ToString(res.Body)\n\tif err != nil {\n\t\tcommon.Throw(rt, err)\n\t}\n\n\tsel, err := html.ParseHTML(rt, body)\n\tif err != nil {\n\t\tcommon.Throw(rt, err)\n\t}\n\tsel.URL = res.URL\n\tif len(selector) > 0 {\n\t\tsel = sel.Find(selector[0])\n\t}\n\treturn sel","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/js/modules/k6/http/response.go#L26-L62","documentation":"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.","triggerScenarios":"Thrown at js/modules/k6/http/response.go:44 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}