gchq/CyberChef · error · OperationError

Invalid co-ordinate format for Degrees Minutes Seconds

Error message

Invalid co-ordinate format for Degrees Minutes Seconds

What it means

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.

Source

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

            // Geodesy needs a space between the first 2 digits and the next letter
            if (/^[\d]{2}[A-Za-z]/.test(input)) {
                input = input.slice(0, 2) + " " + input.slice(2);
            }
            utm = Utm.parse(input);
            latlon = utm.toLatLonE();
            break;
        case "Degrees Minutes Seconds":
            if (isPair) {
                // Split up the lat/long into degrees / minutes / seconds values
                splitLat = splitInput(split[0]);
                splitLong = splitInput(split[1]);

                if (splitLat.length >= 3 && splitLong.length >= 3) {
                    lat = convDMSToDD(splitLat[0], splitLat[1], splitLat[2], 10);
                    lon = convDMSToDD(splitLong[0], splitLong[1], splitLong[2], 10);
                    latlon = new LatLonEllipsoidal(lat.degrees, lon.degrees);
                } else {
                    throw new OperationError("Invalid co-ordinate format for Degrees Minutes Seconds");
                }
            } else {
                // Not a pair, so only try to convert one set of co-ordinates
                splitLat = splitInput(split[0]);
                if (splitLat.length >= 3) {
                    lat = convDMSToDD(splitLat[0], splitLat[1], splitLat[2]);
                    latlon = new LatLonEllipsoidal(lat.degrees, lat.degrees);
                } else {
                    throw new OperationError("Invalid co-ordinate format for Degrees Minutes Seconds");
                }
            }
            break;
        case "Degrees Decimal Minutes":
            if (isPair) {
                splitLat = splitInput(split[0]);
                splitLong = splitInput(split[1]);
                if (splitLat.length !== 2 || splitLong.length !== 2) {
                    throw new OperationError("Invalid co-ordinate format for Degrees Decimal Minutes.");

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Ensure BOTH lat and long segments contain three numeric components (degrees, minutes, seconds).
  2. Switch inFormat to 'Degrees Decimal Minutes' if seconds are genuinely absent.
  3. Pre-validate each half with splitInput and confirm length >= 3 before calling.

Example fix

// before
convertCoordinates("51 30 N, 0 7 W", "Degrees Minutes Seconds", "Direction Preceding", ...);
// lat has 2 numbers, lon has 2 -> throws

// after
convertCoordinates("51 30 26 N, 0 7 39 W", "Degrees Minutes Seconds", "Direction Preceding", ...);
Defensive patterns

Strategy: validation

Validate before calling

function splitInput(input) {
  return input.split(/\s+/).map(s => s.replace(/[^0-9.-]/g, "")).filter(Boolean).map(Number);
}
function assertDmsPair(split) {
  if (splitInput(split[0]).length < 3 || splitInput(split[1]).length < 3) {
    throw new Error("DMS pair needs degrees, minutes, seconds for BOTH halves.");
  }
}

Prevention

When it happens

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

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

Related errors


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