NousResearch/hermes-agent · error
latitude/longitude out of range
Error message
latitude/longitude out of range
What it means
Thrown by buildLocationPayload when the numeric latitude/longitude pass the finite check but fall outside geographic bounds: latitude outside [-90, 90] or longitude outside [-180, 180]. This catches swapped lat/lon, sign errors, and garbage-but-finite numbers before they reach Baileys/WhatsApp.
Source
Thrown at scripts/whatsapp-bridge/bridge_helpers.js:180
const options = {};
const quoted = messageStore?.get(replyTo);
if (quoted?.key && quoted?.message) {
// Baileys expects quoted messages as sendMessage options, not inside the
// message content payload. Keeping this split avoids silently sending a
// literal/ignored `quoted` field instead of a native WhatsApp reply.
options.quoted = quoted;
}
return { content, options };
}
export function buildLocationPayload({ latitude, longitude, name, address } = {}) {
const lat = Number(latitude);
const lon = Number(longitude);
if (!Number.isFinite(lat) || !Number.isFinite(lon)) {
throw new Error('latitude and longitude must be numbers');
}
if (lat < -90 || lat > 90 || lon < -180 || lon > 180) {
throw new Error('latitude/longitude out of range');
}
const location = {
degreesLatitude: lat,
degreesLongitude: lon,
};
if (name) location.name = String(name);
if (address) location.address = String(address);
return { location };
}
function textFromQuotedMessage(quotedMessage) {
if (!quotedMessage) return '';
if (quotedMessage.conversation) return quotedMessage.conversation;
if (quotedMessage.extendedTextMessage?.text) return quotedMessage.extendedTextMessage.text;
if (quotedMessage.imageMessage?.caption) return quotedMessage.imageMessage.caption;
if (quotedMessage.videoMessage?.caption) return quotedMessage.videoMessage.caption;
if (quotedMessage.documentMessage?.caption) return quotedMessage.documentMessage.caption;View on GitHub (pinned to c896c09c42)
Solutions
- Check argument order — latitude comes first and must be within ±90; longitude within ±180.
- Validate ranges at the caller/tool-schema level (minimum/maximum in JSON schema) before invoking the bridge.
- If coordinates come from an external API, verify units are decimal degrees, not DMS or radians.
Example fix
// before
buildLocationPayload({ latitude: -122.4194, longitude: 37.7749 }) // swapped
// after
buildLocationPayload({ latitude: 37.7749, longitude: -122.4194 }) Defensive patterns
Strategy: validation
Validate before calling
function inRange(lat: unknown, lon: unknown): boolean {
const a = Number(lat), b = Number(lon)
return a >= -90 && a <= 90 && b >= -180 && b <= 180
} Type guard
function isGeographicPair(p: { latitude: number; longitude: number }): boolean {
return Math.abs(p.latitude) <= 90 && Math.abs(p.longitude) <= 180
} Try / catch
try {
buildLocationPayload(args)
} catch (e) {
if (e instanceof Error && e.message === 'latitude/longitude out of range')
reply('Check the coordinate order and values (lat ±90, lon ±180).')
else throw e
} Prevention
- Fix argument order at the boundary — latitude first, bounded by ±90.
- Add JSON-schema minimum/maximum bounds for lat/lon in tool definitions.
- Sanity-check |lat| <= 90 before invoking the bridge; the common bug is swapped args.
When it happens
Trigger: Passing longitude as latitude (e.g. lat: -122.4, lon: 37.7 for San Francisco), out-of-range values from a miscalculated source, or strings like '999' that coerce to finite numbers.
Common situations: Lat/lon argument order swapped in a tool call or LLM-generated payload; degrees/minutes strings partially parsed into wrong magnitudes.
Related errors
- latitude and longitude must be numbers
- question is required
- at least two poll options are required
- Preview mode — launching is disabled.
- no install root
AI-assisted analysis of NousResearch/hermes-agent@c896c09c42 (2026-08-14).
Data as JSON: /api/errors/76e446e268c8c25a.
Report an issue: GitHub.