{"record":{"id":"bd34f2a0fa97106a","repo":"gchq/CyberChef","slug":"unable-to-detect-the-input-format-automatically","errorCode":null,"errorMessage":"Unable to detect the input format automatically.","messagePattern":"Unable to detect the input format automatically\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/ConvertCoordinates.mjs","lineNumber":97,"sourceCode":"        precision = 0;\n    }\n\n    if (inDelim === \"Auto\") {\n        // Try to detect a delimiter in the input.\n        inDelim = findDelim(input);\n        if (inDelim === null) {\n            throw new OperationError(\"Unable to detect the input delimiter automatically.\");\n        }\n    } else if (!inDelim.includes(\"Direction\")) {\n        // Convert the delimiter argument value to the actual character\n        inDelim = realDelim(inDelim);\n    }\n\n    if (inFormat === \"Auto\") {\n        // Try to detect the format of the input data\n        inFormat = findFormat(input, inDelim);\n        if (inFormat === null) {\n            throw new OperationError(\"Unable to detect the input format automatically.\");\n        }\n    }\n\n    // Convert the output delimiter argument to the real character\n    outDelim = realDelim(outDelim);\n\n    if (!NO_CHANGE.includes(inFormat)) {\n        if (inDelim.includes(\"Direction\")) {\n            // Split on directions\n            split = input.split(/[NnEeSsWw]/g);\n            if (split[0] === \"\") {\n                // Remove first element if direction preceding\n                split = split.slice(1);\n            }\n        } else {\n            split = input.split(inDelim);\n        }\n        // Replace any co-ordinate symbols with spaces so we can split on them later","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/ConvertCoordinates.mjs#L79-L115","documentation":"Thrown by convertCoordinates when inFormat is 'Auto' and findFormat returns null. findFormat inspects the (delimiter-split) first token: it tries MGRS, OSNG, Geohash, UTM regexes, then falls back to counting numeric parts per segment (3 -> DMS, 2 -> DDM, 1 -> DD). If none match and the numeric count is 0 or >3, it returns null.","triggerScenarios":"convertCoordinates with inFormat='Auto' on input that has no recognisable degree symbols, doesn't match the geohash/MGRS/OSNG/UTM patterns, and whose first segment yields 0 numeric parts (e.g. empty, all letters) or more than 3 numeric tokens.","commonSituations":"Feeding malformed or partial coordinate strings; pasting with stray units like 'deg'/'min' that get stripped to nothing; input where the first segment is blank; very short inputs (single non-numeric char).","solutions":["Supply an explicit inFormat (e.g. 'Decimal Degrees') instead of 'Auto'.","Validate/normalise the input so the first segment contains 1-3 numeric parts.","Check findFormat(input, delim) yourself before calling and warn the user when it returns null."],"exampleFix":"// before\nconvertCoordinates(\"abc\", \"Auto\", \"Auto\", ...); // findFormat -> null\n\n// after\nconvertCoordinates(\"51.5074, -0.1278\", \"Decimal Degrees\", \"Comma\", ...);","handlingStrategy":"validation","validationCode":"import { findFormat, findDelim } from \".../ConvertCoordinates.mjs\";\nif (inFormat === \"Auto\") {\n  const delim = inDelim === \"Auto\" ? findDelim(input) : inDelim;\n  if (findFormat(input, delim) === null) {\n    throw new Error(\"Could not auto-detect format; specify inFormat explicitly.\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  convertCoordinates(input, \"Auto\", inDelim, outFormat, outDelim, includeDir, precision);\n} catch (e) {\n  if (/format/i.test(e.message)) {\n    convertCoordinates(input, \"Decimal Degrees\", inDelim, outFormat, outDelim, includeDir, precision);\n  } else throw e;\n}","preventionTips":["Specify the format explicitly when the data shape is known.","Normalise degree symbols and units before detection.","Provide at least one numeric component per segment."],"tags":["coordinates","geo","input-validation","format-detection"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}