openclaw/openclaw · error
accuracy must be non-negative.
Error message
accuracy must be non-negative.
What it means
Thrown by parseGeolocationOptions when overriding the browser geolocation context. The 'accuracy' field (read first via readRouteFiniteNumber, so it must already be finite) is rejected if it is less than zero, because geolocation accuracy is expressed in meters and is physically non-negative. This is a request-body validation guard for the context mutation route, not a runtime/browser-state error.
Source
Thrown at extensions/browser/src/browser/routes/agent.storage.ts:167
if (clear) {
return { clear };
}
const origin = readOptionalHttpOrigin(body.origin);
const latitude = assertRange(
readRouteFiniteNumber(body.latitude, "latitude"),
"latitude",
-90,
90,
);
const longitude = assertRange(
readRouteFiniteNumber(body.longitude, "longitude"),
"longitude",
-180,
180,
);
const accuracy = readRouteFiniteNumber(body.accuracy, "accuracy");
if (accuracy !== undefined && accuracy < 0) {
throw new Error("accuracy must be non-negative.");
}
if (!clear && (latitude === undefined || longitude === undefined)) {
throw new Error("latitude and longitude are required (or set clear=true)");
}
return { clear, latitude, longitude, accuracy, origin };
}
/** Register storage and browser-context mutation endpoints. */
export function registerBrowserAgentStorageRoutes(
app: BrowserRouteRegistrar,
ctx: BrowserRouteContext,
) {
app.get("/cookies", async (req, res) => {
const targetId = resolveTargetIdFromQuery(req.query);
await withPlaywrightRouteContext({
req,
res,
ctx,View on GitHub (pinned to 01804a7531)
Solutions
- Omit the accuracy field entirely if you do not need to override it.
- Send a non-negative finite number for accuracy (e.g. 10).
- If the intent is to remove an existing geolocation override, send clear=true instead of a negative accuracy.
Example fix
// before
fetch('/browser/agent/storage/geolocation', { method: 'POST', body: JSON.stringify({ latitude: 37.77, longitude: -122.41, accuracy: -1 }) });
// after
fetch('/browser/agent/storage/geolocation', { method: 'POST', body: JSON.stringify({ latitude: 37.77, longitude: -122.41, accuracy: 10 }) }); Defensive patterns
Strategy: validation
Validate before calling
function safeAccuracy(value: unknown): number | undefined {
if (value == null) return undefined;
const n = Number(value);
if (!Number.isFinite(n)) {
throw new Error('accuracy must be a finite number');
}
if (n < 0) {
throw new Error('accuracy must be non-negative');
}
return n;
}
// build body: const accuracy = safeAccuracy(raw.accuracy); Type guard
function isValidAccuracy(v: unknown): v is number {
return typeof v === 'number' && Number.isFinite(v) && v >= 0;
} Prevention
- Normalize 'unset' numerics to undefined rather than -1 before posting.
- Validate accuracy >= 0 client-side with the same finite-number check the server uses.
- Use clear=true to remove an override instead of sending sentinel values.
When it happens
Trigger: POST to a browser agent storage/context-mutation endpoint with body.accuracy set to a negative number (e.g. -1) while body.clear is falsy. Trigger fires only when accuracy is a real number (non-null); undefined accuracy is allowed.
Common situations: Using -1 as an 'unset' sentinel for accuracy; sign mistakes when copying coordinates; fuzz/testing with arbitrary negative values; client code that defaults unset numerics to -1.
Related errors
- latitude and longitude are required (or set clear=true)
- ${fieldName} must be a finite number.
- ${fieldName} must be an integer.
- ${fieldName} must be a positive integer.
- ${fieldName} must be a non-negative integer.
AI-assisted analysis of openclaw/openclaw@01804a7531 (2026-08-12).
Data as JSON: /api/errors/3e02c4357f1807eb.
Report an issue: GitHub.