{"record":{"id":"3482f5df6938da10","repo":"grafana/k6","slug":"invalid-accuracy-2f-precondition-0-accurac","errorCode":null,"errorMessage":"invalid accuracy \"%.2f\": precondition 0 <= ACCURACY failed","messagePattern":"invalid accuracy \"%\\.2f\": precondition 0 <= ACCURACY failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_context_options.go","lineNumber":82,"sourceCode":"\tif p == nil {\n\t\treturn nil\n\t}\n\tif strings.TrimSpace(p.Server) == \"\" {\n\t\treturn fmt.Errorf(\"proxy.server must be set\")\n\t}\n\treturn nil\n}\n\n// Validate validates the [Geolocation].\nfunc (g *Geolocation) Validate() error {\n\tif g.Longitude < -180 || g.Longitude > 180 {\n\t\treturn fmt.Errorf(`invalid longitude \"%.2f\": precondition -180 <= LONGITUDE <= 180 failed`, g.Longitude)\n\t}\n\tif g.Latitude < -90 || g.Latitude > 90 {\n\t\treturn fmt.Errorf(`invalid latitude \"%.2f\": precondition -90 <= LATITUDE <= 90 failed`, g.Latitude)\n\t}\n\tif g.Accuracy < 0 {\n\t\treturn fmt.Errorf(`invalid accuracy \"%.2f\": precondition 0 <= ACCURACY failed`, g.Accuracy)\n\t}\n\treturn nil\n}\n\n// GrantPermissionsOptions is used by BrowserContext.GrantPermissions.\ntype GrantPermissionsOptions struct {\n\tOrigin string\n}\n","sourceCodeStart":64,"sourceCodeEnd":91,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser_context_options.go#L64-L91","documentation":"Validation error from Geolocation.Validate: the accuracy field of the geolocation override is negative. Accuracy is optional and measured in meters; k6 requires it to be >= 0 when provided (a sensible non-negative precondition matching Playwright's contract).","triggerScenarios":"browser.newContext({ geolocation: { latitude: 10, longitude: 10, accuracy: -1 } }); passing -1 as a sentinel 'unset' value; arithmetic that computes accuracy as a difference which goes negative.","commonSituations":"Using -1 or 0-minus defaults for optional numeric fields out of habit; computing accuracy from external sensor-like data without clamping; copying fixtures from another system that used -1 for unknown accuracy.","solutions":["Remove the accuracy field entirely if you don't need it, or pass a non-negative value like accuracy: 100.","Clamp computed values: Math.max(0, accuracy).","Use 0 (or omit) rather than -1 to express 'no accuracy hint'."],"exampleFix":"// before\ncontext.setGeolocation({ latitude: 35.68, longitude: 139.69, accuracy: -1 });\n\n// after\ncontext.setGeolocation({ latitude: 35.68, longitude: 139.69, accuracy: 100 });\n// or omit accuracy entirely","handlingStrategy":"validation","validationCode":"function isValidAccuracy(a) {\n  return a == null || (Number.isFinite(a) && a >= 0);\n}\nif (!isValidAccuracy(geo.accuracy)) {\n  geo = { ...geo, accuracy: Math.max(0, geo.accuracy) }; // or drop the field\n}\ncontext.setGeolocation(geo);","typeGuard":"function hasValidAccuracy(g) {\n  return g.accuracy == null || (Number.isFinite(g.accuracy) && g.accuracy >= 0);\n}","tryCatchPattern":null,"preventionTips":["Omit accuracy unless you actually need it.","Never use -1 as an 'unset' marker for accuracy; omit the field instead.","Clamp computed accuracy values to >= 0 before passing them in."],"tags":["geolocation","validation","browser-context"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}