gchq/CyberChef · error · OperationError

Unknown input format '${inFormat}'

Error message

Unknown input format '${inFormat}'

What it means

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.

Source

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

        case "Decimal Degrees":
            if (isPair) {
                splitLat =  splitInput(split[0]);
                splitLong = splitInput(split[1]);
                if (splitLat.length !== 1 || splitLong.length !== 1) {
                    throw new OperationError("Invalid co-ordinate format for Decimal Degrees.");
                }
                latlon = new LatLonEllipsoidal(splitLat[0], splitLong[0]);
            } else {
                // Not a pair, so only try to convert one set of co-ordinates
                splitLat = splitInput(split[0]);
                if (splitLat.length !== 1) {
                    throw new OperationError("Invalid co-ordinate format for Decimal Degrees.");
                }
                latlon = new LatLonEllipsoidal(splitLat[0], splitLat[0]);
            }
            break;
        default:
            throw new OperationError(`Unknown input format '${inFormat}'`);
    }

    // Everything is now a geodesy latlon object
    // These store the latitude and longitude as decimal
    if (inFormat.includes("Degrees")) {
        // If the input string contains directions, we need to check if they're S or W.
        // If either of the directions are, we should make the decimal value negative
        const dirs = input.toUpperCase().match(/[NESW]/g);
        if (dirs && dirs.length >= 1) {
            // Make positive lat/lon values with S/W directions into negative values
            if (dirs[0] === "S" || dirs[0] === "W" && latlon.lat > 0) {
                latlon.lat = -latlon.lat;
            }
            if (dirs.length >= 2) {
                if (dirs[1] === "S" || dirs[1] === "W" && latlon.lon > 0) {
                    latlon.lon = -latlon.lon;
                }
            }

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Use one of the exact canonical format names from the FORMATS export.
  2. If accepting user input, validate against FORMATS.includes(inFormat) before calling.
  3. Default to 'Auto' detection when the format is uncertain.

Example fix

// before
convertCoordinates(coords, "DMS", ...); // not a recognised case -> throws

// after
import { FORMATS } from "...ConvertCoordinates.mjs";
convertCoordinates(coords, "Degrees Minutes Seconds", ...);
Defensive patterns

Strategy: type-guard

Validate before calling

import { FORMATS } from ".../ConvertCoordinates.mjs";
if (!FORMATS.includes(inFormat)) {
  throw new Error(`Unknown inFormat '${inFormat}'. Valid: ${FORMATS.join(", ")}`);
}

Type guard

function isKnownFormat(f) {
  const FORMATS = ["Degrees Minutes Seconds","Degrees Decimal Minutes","Decimal Degrees","Geohash","Military Grid Reference System","Ordnance Survey National Grid","Universal Transverse Mercator"];
  return typeof f === "string" && FORMATS.includes(f);
}

Prevention

When it happens

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

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

Related errors


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