gchq/CyberChef · error · OperationError

Unable to detect the input format automatically.

Error message

Unable to detect the input format automatically.

What it means

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.

Source

Thrown at src/core/lib/ConvertCoordinates.mjs:97

        precision = 0;
    }

    if (inDelim === "Auto") {
        // Try to detect a delimiter in the input.
        inDelim = findDelim(input);
        if (inDelim === null) {
            throw new OperationError("Unable to detect the input delimiter automatically.");
        }
    } else if (!inDelim.includes("Direction")) {
        // Convert the delimiter argument value to the actual character
        inDelim = realDelim(inDelim);
    }

    if (inFormat === "Auto") {
        // Try to detect the format of the input data
        inFormat = findFormat(input, inDelim);
        if (inFormat === null) {
            throw new OperationError("Unable to detect the input format automatically.");
        }
    }

    // Convert the output delimiter argument to the real character
    outDelim = realDelim(outDelim);

    if (!NO_CHANGE.includes(inFormat)) {
        if (inDelim.includes("Direction")) {
            // Split on directions
            split = input.split(/[NnEeSsWw]/g);
            if (split[0] === "") {
                // Remove first element if direction preceding
                split = split.slice(1);
            }
        } else {
            split = input.split(inDelim);
        }
        // Replace any co-ordinate symbols with spaces so we can split on them later

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Supply an explicit inFormat (e.g. 'Decimal Degrees') instead of 'Auto'.
  2. Validate/normalise the input so the first segment contains 1-3 numeric parts.
  3. Check findFormat(input, delim) yourself before calling and warn the user when it returns null.

Example fix

// before
convertCoordinates("abc", "Auto", "Auto", ...); // findFormat -> null

// after
convertCoordinates("51.5074, -0.1278", "Decimal Degrees", "Comma", ...);
Defensive patterns

Strategy: validation

Validate before calling

import { findFormat, findDelim } from ".../ConvertCoordinates.mjs";
if (inFormat === "Auto") {
  const delim = inDelim === "Auto" ? findDelim(input) : inDelim;
  if (findFormat(input, delim) === null) {
    throw new Error("Could not auto-detect format; specify inFormat explicitly.");
  }
}

Try / catch

try {
  convertCoordinates(input, "Auto", inDelim, outFormat, outDelim, includeDir, precision);
} catch (e) {
  if (/format/i.test(e.message)) {
    convertCoordinates(input, "Decimal Degrees", inDelim, outFormat, outDelim, includeDir, precision);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/bd34f2a0fa97106a. Report an issue: GitHub.