{"record":{"id":"1f88f6ca3e106ae2","repo":"grafana/k6","slug":"parsing-setchecked-options-w","errorCode":null,"errorMessage":"parsing setChecked options: %w","messagePattern":"parsing setChecked options: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/element_handle_mapping.go","lineNumber":224,"sourceCode":"\t\t\t\treturn nil, fmt.Errorf(\"parsing selectOption options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn eh.SelectOption(convValues, popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"selectText\": func(opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts := common.NewElementHandleBaseOptions(eh.DefaultTimeout())\n\t\t\tif err := popts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing selectText options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, eh.SelectText(popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"setChecked\": func(checked bool, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts := common.NewElementHandleSetCheckedOptions(eh.DefaultTimeout())\n\t\t\tif err := popts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing setChecked options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, eh.SetChecked(checked, popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"setInputFiles\": func(files sobek.Value, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts := common.NewElementHandleSetInputFilesOptions(eh.DefaultTimeout())\n\t\t\tif err := popts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing setInputFiles options: %w\", err)\n\t\t\t}\n\t\t\tvar pfiles common.Files\n\t\t\tif err := pfiles.Parse(vu.Context(), files); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing setInputFiles parameter: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, eh.SetInputFiles(&pfiles, popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/element_handle_mapping.go#L206-L242","documentation":"Thrown synchronously by ElementHandle.setChecked() when its options fail to parse. setChecked uses ElementHandleSetCheckedOptions, which embeds the base-pointer options; in common/element_handle_options.go the only Parse step that can return an error is exporting 'position' to map[string]float64 (strict/force/noWaitAfter/timeout/trial are lenient coercions). The mapping returns (nil, error), so it throws at call time rather than rejecting a promise.","triggerScenarios":"el.setChecked(true, { position: 'center' }), { position: { x: '1', y: 2 } }, or position as array/number/boolean. Everything else in the options object is coerced and cannot produce this error.","commonSituations":"Sharing one options literal between click() and setChecked() where the position field was serialized to a string; coordinate values coming from CSV/JSON fixtures without numeric conversion.","solutions":["Pass position as { x: <number>, y: <number> } or omit it","Coerce fixture coordinates with Number() and validate with Number.isFinite","Guard options with a shared isPosition check for all pointer-based element actions","Use try/catch around the call since the throw is synchronous"],"exampleFix":"// before\nawait el.setChecked(true, { position: 'center', strict: true });\n\n// after\nawait el.setChecked(true, { strict: true });","handlingStrategy":"type-guard","validationCode":"const p = opts?.position;\nif (p !== undefined && (typeof p !== 'object' || Array.isArray(p) ||\n    !Number.isFinite(Number(p.x)) || !Number.isFinite(Number(p.y)))) {\n  throw new Error('setChecked(): position must be { x: number, y: number }');\n}","typeGuard":"function isSetCheckedOpts(o) {\n  if (o == null) return true;\n  const posOk = o.position === undefined ||\n    (typeof o.position === 'object' && !Array.isArray(o.position) &&\n     Number.isFinite(Number(o.position.x)) && Number.isFinite(Number(o.position.y)));\n  const strictOk = o.strict === undefined || typeof o.strict === 'boolean';\n  return posOk && strictOk;\n}","tryCatchPattern":"try {\n  await el.setChecked(shouldCheck, opts);\n} catch (e) {\n  if (/parsing setChecked options/.test(String(e.message))) {\n    console.log(`fix setChecked options: ${e.message}`);\n  } else throw e;\n}","preventionTips":["Only position can fail parsing here; strict is a lenient boolean coercion","Share one options builder between check/setChecked/uncheck so position stays numeric everywhere","Use try/catch: the error is thrown synchronously, not via promise rejection"],"tags":["k6","browser","element-handle","set-checked","option-parsing"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}