{"record":{"id":"75371aefb5e401bd","repo":"gchq/CyberChef","slug":"invalid-co-ordinate-format-for-degrees-minutes-sec","errorCode":null,"errorMessage":"Invalid co-ordinate format for Degrees Minutes Seconds","messagePattern":"Invalid co-ordinate format for Degrees Minutes Seconds","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/ConvertCoordinates.mjs","lineNumber":161,"sourceCode":"            // Geodesy needs a space between the first 2 digits and the next letter\n            if (/^[\\d]{2}[A-Za-z]/.test(input)) {\n                input = input.slice(0, 2) + \" \" + input.slice(2);\n            }\n            utm = Utm.parse(input);\n            latlon = utm.toLatLonE();\n            break;\n        case \"Degrees Minutes Seconds\":\n            if (isPair) {\n                // Split up the lat/long into degrees / minutes / seconds values\n                splitLat = splitInput(split[0]);\n                splitLong = splitInput(split[1]);\n\n                if (splitLat.length >= 3 && splitLong.length >= 3) {\n                    lat = convDMSToDD(splitLat[0], splitLat[1], splitLat[2], 10);\n                    lon = convDMSToDD(splitLong[0], splitLong[1], splitLong[2], 10);\n                    latlon = new LatLonEllipsoidal(lat.degrees, lon.degrees);\n                } else {\n                    throw new OperationError(\"Invalid co-ordinate format for Degrees Minutes Seconds\");\n                }\n            } else {\n                // Not a pair, so only try to convert one set of co-ordinates\n                splitLat = splitInput(split[0]);\n                if (splitLat.length >= 3) {\n                    lat = convDMSToDD(splitLat[0], splitLat[1], splitLat[2]);\n                    latlon = new LatLonEllipsoidal(lat.degrees, lat.degrees);\n                } else {\n                    throw new OperationError(\"Invalid co-ordinate format for Degrees Minutes Seconds\");\n                }\n            }\n            break;\n        case \"Degrees Decimal Minutes\":\n            if (isPair) {\n                splitLat = splitInput(split[0]);\n                splitLong = splitInput(split[1]);\n                if (splitLat.length !== 2 || splitLong.length !== 2) {\n                    throw new OperationError(\"Invalid co-ordinate format for Degrees Decimal Minutes.\");","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/ConvertCoordinates.mjs#L143-L179","documentation":"Thrown in the 'Degrees Minutes Seconds' branch when isPair is true but splitInput of either the latitude or longitude segment returns fewer than 3 numeric parts. DMS requires degrees, minutes, and seconds (>= 3 numbers) for BOTH halves of the pair.","triggerScenarios":"inFormat='Degrees Minutes Seconds' with a pair input (split.length > 1) where one half is missing the seconds value (e.g. '51 30, 0 7') or contains non-numeric junk that gets stripped to <3 numbers.","commonSituations":"Pasting DMS without seconds ('51°30' N, 0°7' W'); using degree symbols inconsistently so one field collapses; truncating one coordinate; mixed separators causing one half to be empty.","solutions":["Ensure BOTH lat and long segments contain three numeric components (degrees, minutes, seconds).","Switch inFormat to 'Degrees Decimal Minutes' if seconds are genuinely absent.","Pre-validate each half with splitInput and confirm length >= 3 before calling."],"exampleFix":"// before\nconvertCoordinates(\"51 30 N, 0 7 W\", \"Degrees Minutes Seconds\", \"Direction Preceding\", ...);\n// lat has 2 numbers, lon has 2 -> throws\n\n// after\nconvertCoordinates(\"51 30 26 N, 0 7 39 W\", \"Degrees Minutes Seconds\", \"Direction Preceding\", ...);","handlingStrategy":"validation","validationCode":"function splitInput(input) {\n  return input.split(/\\s+/).map(s => s.replace(/[^0-9.-]/g, \"\")).filter(Boolean).map(Number);\n}\nfunction assertDmsPair(split) {\n  if (splitInput(split[0]).length < 3 || splitInput(split[1]).length < 3) {\n    throw new Error(\"DMS pair needs degrees, minutes, seconds for BOTH halves.\");\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Include seconds in both latitude and longitude.","Verify each half yields >= 3 numeric tokens before calling.","Use DDM/DD format if seconds are unavailable."],"tags":["coordinates","geo","input-validation","dms"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}