{"record":{"id":"7d65fccdb45e5d5f","repo":"gchq/CyberChef","slug":"error-converting-co-ordinates","errorCode":null,"errorMessage":"Error converting co-ordinates.","messagePattern":"Error converting co-ordinates\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/ConvertCoordinates.mjs","lineNumber":296,"sourceCode":"                throw new OperationError(\"Could not convert co-ordinates to OS National Grid. Are the co-ordinates in range?\");\n            }\n            // OSNG wants a precision that's an even number between 2 and 10\n            if (precision % 2 !== 0) {\n                precision = precision + 1;\n            }\n            if (precision > 10) {\n                precision = 10;\n            }\n            convLat = osng.toString(precision);\n            break;\n        case \"Universal Transverse Mercator\":\n            utm = latlon.toUtm();\n            convLat = utm.toString(precision);\n            break;\n    }\n\n    if (convLat === undefined) {\n        throw new OperationError(\"Error converting co-ordinates.\");\n    }\n\n    if (outFormat.includes(\"Degrees\")) {\n        // Format DD/DDM/DMS for output\n        // If we're outputting a compass direction, remove the negative sign\n        if (latDir === \"S\" && includeDir !== \"None\") {\n            convLat = convLat.replace(\"-\", \"\");\n        }\n        if (longDir === \"W\" && includeDir !== \"None\") {\n            convLon = convLon.replace(\"-\", \"\");\n        }\n\n        let outConv = \"\";\n        if (includeDir === \"Before\") {\n            outConv += latDir + \" \";\n        }\n\n        outConv += convLat;","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/ConvertCoordinates.mjs#L278-L314","documentation":"Thrown after the outFormat switch when convLat is still undefined, meaning none of the output-format cases executed. This happens when outFormat is not one of the recognised cases ('Decimal Degrees', 'Degrees Decimal Minutes', 'Degrees Minutes Seconds', 'Geohash', 'Military Grid Reference System', 'Ordnance Survey National Grid', 'Universal Transverse Mercator') — the switch has no default, so convLat is never assigned.","triggerScenarios":"convertCoordinates called with an outFormat that is misspelled, wrong case, null/undefined, or otherwise not a canonical format name. The outFormat switch silently matches no case and convLat stays undefined.","commonSituations":"Hardcoding an output format string that doesn't match the canonical names; passing user-supplied output format without validation; case mismatch (e.g. 'decimal degrees'); undefined outFormat from a missing argument.","solutions":["Use a canonical output format name from the FORMATS export.","Validate FORMATS.includes(outFormat) before calling.","Check that outFormat is a non-empty string and not null/undefined."],"exampleFix":"// before\nconvertCoordinates(coords, \"Decimal Degrees\", \"Comma\", \"wgs84\", ...);\n// 'wgs84' matches no case -> convLat undefined -> throws\n\n// after\nconvertCoordinates(coords, \"Decimal Degrees\", \"Comma\", \"Decimal Degrees\", ...);","handlingStrategy":"type-guard","validationCode":"import { FORMATS } from \".../ConvertCoordinates.mjs\";\nif (!FORMATS.includes(outFormat)) {\n  throw new Error(`Unknown outFormat '${outFormat}'. Valid: ${FORMATS.join(\", \")}`);\n}","typeGuard":"function isKnownFormat(f) {\n  const FORMATS = [\"Degrees Minutes Seconds\",\"Degrees Decimal Minutes\",\"Decimal Degrees\",\"Geohash\",\"Military Grid Reference System\",\"Ordnance Survey National Grid\",\"Universal Transverse Mercator\"];\n  return typeof f === \"string\" && FORMATS.includes(f);\n}","tryCatchPattern":null,"preventionTips":["Source outFormat from the FORMATS export.","Validate outFormat is a non-empty string before calling.","Treat an unrecognised outFormat as a programmer/config error, not user input."],"tags":["coordinates","geo","input-validation","output-format","enum"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}