{"record":{"id":"501cd4199183f6e1","repo":"grafana/k6","slug":"disposing-element-handle-w","errorCode":null,"errorMessage":"disposing element handle: %w","messagePattern":"disposing element handle: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1239,"sourceCode":"\t\tforceCallable: true,\n\t\treturnByValue: false,\n\t}\n\tresult, err := h.evalWithScript(h.ctx, opts, querySelector, parsedSelector, strict)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"querying selector %q: %w\", selector, err)\n\t}\n\tif result == nil {\n\t\treturn nil, nil //nolint:nilnil\n\t}\n\thandle, ok := result.(JSHandleAPI)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"querying selector %q, wrong type %T\", selector, result)\n\t}\n\telement := handle.AsElement()\n\tif element == nil {\n\t\tdefer func() {\n\t\t\tif err := handle.Dispose(); err != nil {\n\t\t\t\terr = fmt.Errorf(\"disposing element handle: %w\", err)\n\t\t\t\trerr = errors.Join(err, rerr)\n\t\t\t}\n\t\t}()\n\t\treturn nil, fmt.Errorf(\"querying selector %q\", selector)\n\t}\n\n\treturn element, nil\n}\n\n// QueryAll queries element subtree for matching elements.\n// If no element matches the selector, the return value resolves to \"null\".\nfunc (h *ElementHandle) QueryAll(selector string) ([]*ElementHandle, error) {\n\thandles, err := h.queryAll(selector, h.evalWithScript)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"querying all selector %q: %w\", selector, err)\n\t}\n\n\treturn handles, nil","sourceCodeStart":1221,"sourceCodeEnd":1257,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/element_handle.go#L1221-L1257","documentation":"Produced inside a deferred cleanup in ElementHandle.Query: the evaluation produced a JSHandle, but handle.AsElement() returned nil (the result is a non-element JS value, e.g. null or a text node wrapper), so the code disposes the handle before reporting failure. This error wraps a Dispose failure on that already-unwanted handle; the dispose error is joined with the query error via errors.Join.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/element_handle.go:1239 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check whether the selector actually matches an element (not text or document node)","Ignore dispose failures during cleanup; they usually mean the target/context was already destroyed","Re-query with a corrected selector once the underlying query error is addressed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}