gchq/CyberChef · error · OperationError
Error converting co-ordinates.
Error message
Error converting co-ordinates.
What it means
Thrown after the outFormat switch when convLat is still undefined, meaning none of the output-format cases executed. This happens when outFormat is not one of the recognised cases ('Decimal Degrees', 'Degrees Decimal Minutes', 'Degrees Minutes Seconds', 'Geohash', 'Military Grid Reference System', 'Ordnance Survey National Grid', 'Universal Transverse Mercator') — the switch has no default, so convLat is never assigned.
Source
Thrown at src/core/lib/ConvertCoordinates.mjs:296
throw new OperationError("Could not convert co-ordinates to OS National Grid. Are the co-ordinates in range?");
}
// OSNG wants a precision that's an even number between 2 and 10
if (precision % 2 !== 0) {
precision = precision + 1;
}
if (precision > 10) {
precision = 10;
}
convLat = osng.toString(precision);
break;
case "Universal Transverse Mercator":
utm = latlon.toUtm();
convLat = utm.toString(precision);
break;
}
if (convLat === undefined) {
throw new OperationError("Error converting co-ordinates.");
}
if (outFormat.includes("Degrees")) {
// Format DD/DDM/DMS for output
// If we're outputting a compass direction, remove the negative sign
if (latDir === "S" && includeDir !== "None") {
convLat = convLat.replace("-", "");
}
if (longDir === "W" && includeDir !== "None") {
convLon = convLon.replace("-", "");
}
let outConv = "";
if (includeDir === "Before") {
outConv += latDir + " ";
}
outConv += convLat;View on GitHub (pinned to 4290ea7539)
Solutions
- Use a canonical output format name from the FORMATS export.
- Validate FORMATS.includes(outFormat) before calling.
- Check that outFormat is a non-empty string and not null/undefined.
Example fix
// before convertCoordinates(coords, "Decimal Degrees", "Comma", "wgs84", ...); // 'wgs84' matches no case -> convLat undefined -> throws // after convertCoordinates(coords, "Decimal Degrees", "Comma", "Decimal Degrees", ...);
Defensive patterns
Strategy: type-guard
Validate before calling
import { FORMATS } from ".../ConvertCoordinates.mjs";
if (!FORMATS.includes(outFormat)) {
throw new Error(`Unknown outFormat '${outFormat}'. 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
- Source outFormat from the FORMATS export.
- Validate outFormat is a non-empty string before calling.
- Treat an unrecognised outFormat as a programmer/config error, not user input.
When it happens
Trigger: convertCoordinates called with an outFormat that is misspelled, wrong case, null/undefined, or otherwise not a canonical format name. The outFormat switch silently matches no case and convLat stays undefined.
Common situations: Hardcoding an output format string that doesn't match the canonical names; passing user-supplied output format without validation; case mismatch (e.g. 'decimal degrees'); undefined outFormat from a missing argument.
Related errors
- Unknown input format '${inFormat}'
- Unable to detect the input delimiter automatically.
- Unable to detect the input format automatically.
- Invalid co-ordinate format for Degrees Minutes Seconds
- Invalid co-ordinate format for Degrees Decimal Minutes.
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/7d65fccdb45e5d5f.
Report an issue: GitHub.