{"record":{"id":"ec7a8bd0e9a79fa3","repo":"NousResearch/hermes-agent","slug":"latitude-and-longitude-must-be-numbers","errorCode":null,"errorMessage":"latitude and longitude must be numbers","messagePattern":"latitude and longitude must be numbers","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/whatsapp-bridge/bridge_helpers.js","lineNumber":177,"sourceCode":"\nexport function buildTextSendPayload(text, { replyTo, messageStore } = {}) {\n  const content = { text };\n  const options = {};\n  const quoted = messageStore?.get(replyTo);\n  if (quoted?.key && quoted?.message) {\n    // Baileys expects quoted messages as sendMessage options, not inside the\n    // message content payload. Keeping this split avoids silently sending a\n    // literal/ignored `quoted` field instead of a native WhatsApp reply.\n    options.quoted = quoted;\n  }\n  return { content, options };\n}\n\nexport function buildLocationPayload({ latitude, longitude, name, address } = {}) {\n  const lat = Number(latitude);\n  const lon = Number(longitude);\n  if (!Number.isFinite(lat) || !Number.isFinite(lon)) {\n    throw new Error('latitude and longitude must be numbers');\n  }\n  if (lat < -90 || lat > 90 || lon < -180 || lon > 180) {\n    throw new Error('latitude/longitude out of range');\n  }\n\n  const location = {\n    degreesLatitude: lat,\n    degreesLongitude: lon,\n  };\n  if (name) location.name = String(name);\n  if (address) location.address = String(address);\n  return { location };\n}\n\nfunction textFromQuotedMessage(quotedMessage) {\n  if (!quotedMessage) return '';\n  if (quotedMessage.conversation) return quotedMessage.conversation;\n  if (quotedMessage.extendedTextMessage?.text) return quotedMessage.extendedTextMessage.text;","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/NousResearch/hermes-agent/blob/c896c09c42910c584c4c7d2325b58c14713ea42c/scripts/whatsapp-bridge/bridge_helpers.js#L159-L195","documentation":"Thrown by buildLocationPayload in the WhatsApp bridge helpers when latitude/longitude cannot be coerced to finite numbers (Number() yields NaN, undefined, or Infinity). It guards before building the Baileys location message, which requires numeric degreesLatitude/degreesLongitude.","triggerScenarios":"Sending a WhatsApp location message via the bridge with latitude/longitude missing, non-numeric strings ('abc'), null, or empty values in the send-location payload.","commonSituations":"Agent/tool call omitting lat/lon fields, geocoding step failing upstream and passing undefined through, or sending place name only without coordinates.","solutions":["Supply numeric latitude and longitude in the location payload (validate with Number.isFinite first).","If only a place name is known, geocode it to coordinates before calling the bridge.","In tool schemas, mark latitude/longitude as required numeric properties so the model cannot omit them."],"exampleFix":"// before\nbuildLocationPayload({ name: 'Office' })\n\n// after\nbuildLocationPayload({ latitude: 37.7749, longitude: -122.4194, name: 'Office' })","handlingStrategy":"validation","validationCode":"function isValidLatLng(lat: unknown, lon: unknown): boolean {\n  const a = Number(lat), b = Number(lon)\n  return Number.isFinite(a) && Number.isFinite(b)\n}","typeGuard":"function hasCoordinates(p: { latitude?: unknown; longitude?: unknown }): p is { latitude: number; longitude: number } {\n  return Number.isFinite(Number(p.latitude)) && Number.isFinite(Number(p.longitude))\n}","tryCatchPattern":"try {\n  buildLocationPayload(args)\n} catch (e) {\n  if (e instanceof Error && e.message === 'latitude and longitude must be numbers')\n    reply('Send me numeric latitude and longitude.')\n  else throw e\n}","preventionTips":["Declare latitude/longitude as required numeric fields in tool schemas (type: number).","Geocode place names to coordinates before attempting a location send.","Unit-test the bridge helper with missing/NaN inputs."],"tags":["whatsapp","bridge","location","validation"],"backgroundTag":null,"analyzedSha":"c896c09c42910c584c4c7d2325b58c14713ea42c","analyzedAt":"2026-08-14T17:18:01.089Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}