{"record":{"id":"46e87a94b32199a6","repo":"gchq/CyberChef","slug":"unknown-input-format-informat","errorCode":null,"errorMessage":"Unknown input format '${inFormat}'","messagePattern":"Unknown input format '(.+?)'","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/ConvertCoordinates.mjs","lineNumber":213,"sourceCode":"        case \"Decimal Degrees\":\n            if (isPair) {\n                splitLat =  splitInput(split[0]);\n                splitLong = splitInput(split[1]);\n                if (splitLat.length !== 1 || splitLong.length !== 1) {\n                    throw new OperationError(\"Invalid co-ordinate format for Decimal Degrees.\");\n                }\n                latlon = new LatLonEllipsoidal(splitLat[0], splitLong[0]);\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 !== 1) {\n                    throw new OperationError(\"Invalid co-ordinate format for Decimal Degrees.\");\n                }\n                latlon = new LatLonEllipsoidal(splitLat[0], splitLat[0]);\n            }\n            break;\n        default:\n            throw new OperationError(`Unknown input format '${inFormat}'`);\n    }\n\n    // Everything is now a geodesy latlon object\n    // These store the latitude and longitude as decimal\n    if (inFormat.includes(\"Degrees\")) {\n        // If the input string contains directions, we need to check if they're S or W.\n        // If either of the directions are, we should make the decimal value negative\n        const dirs = input.toUpperCase().match(/[NESW]/g);\n        if (dirs && dirs.length >= 1) {\n            // Make positive lat/lon values with S/W directions into negative values\n            if (dirs[0] === \"S\" || dirs[0] === \"W\" && latlon.lat > 0) {\n                latlon.lat = -latlon.lat;\n            }\n            if (dirs.length >= 2) {\n                if (dirs[1] === \"S\" || dirs[1] === \"W\" && latlon.lon > 0) {\n                    latlon.lon = -latlon.lon;\n                }\n            }","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/ConvertCoordinates.mjs#L195-L231","documentation":"Thrown by convertCoordinates in the default case of its inFormat switch: the supplied inFormat string did not match any known format case ('Geohash', 'Military Grid Reference System', 'Ordnance Survey National Grid', 'Universal Transverse Mercator', 'Degrees Minutes Seconds', 'Degrees Decimal Minutes', 'Decimal Degrees'). Note the message uses a template literal but the thrown string still contains the literal '${inFormat}' substring only if interpolation is absent — here it interpolates the actual value.","triggerScenarios":"convertCoordinates called with an inFormat that is misspelled, abbreviated, in a different case, or not in the FORMATS list — e.g. 'DMS', 'decdeg', 'GeohAsh', null, or undefined.","commonSituations":"Hardcoding a format string that drifts from the canonical names; passing a user-typed format without validation; case sensitivity mismatches; passing undefined when inFormat is not supplied.","solutions":["Use one of the exact canonical format names from the FORMATS export.","If accepting user input, validate against FORMATS.includes(inFormat) before calling.","Default to 'Auto' detection when the format is uncertain."],"exampleFix":"// before\nconvertCoordinates(coords, \"DMS\", ...); // not a recognised case -> throws\n\n// after\nimport { FORMATS } from \"...ConvertCoordinates.mjs\";\nconvertCoordinates(coords, \"Degrees Minutes Seconds\", ...);","handlingStrategy":"type-guard","validationCode":"import { FORMATS } from \".../ConvertCoordinates.mjs\";\nif (!FORMATS.includes(inFormat)) {\n  throw new Error(`Unknown inFormat '${inFormat}'. 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":["Always source inFormat from the FORMATS export, never hand-typed strings.","Validate user-supplied format strings against FORMATS before calling.","Default to 'Auto' when format is uncertain."],"tags":["coordinates","geo","input-validation","enum"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}