gchq/CyberChef · error · OperationError
Unrecognised unit
Error message
Unrecognised unit
What it means
To UNIX Timestamp maps the selected Units argument to a multiplication of the moment value. If Units is none of the supported strings ('Seconds (s)', 'Milliseconds (ms)', 'Microseconds (μs)', 'Nanoseconds (ns)'), the final else branch throws 'Unrecognised unit'. This typically indicates the option list was changed or the argument was supplied programmatically with an invalid value.
Source
Thrown at src/core/operations/ToUNIXTimestamp.mjs:70
*
* @throws {OperationError} if unit unrecognised
*/
run(input, args) {
const [units, treatAsUTC, showDateTime] = args,
d = treatAsUTC ? moment.utc(input) : moment(input);
let result = "";
if (units === "Seconds (s)") {
result = d.unix();
} else if (units === "Milliseconds (ms)") {
result = d.valueOf();
} else if (units === "Microseconds (μs)") {
result = d.valueOf() * 1000;
} else if (units === "Nanoseconds (ns)") {
result = d.valueOf() * 1000000;
} else {
throw new OperationError("Unrecognised unit");
}
return showDateTime ? `${result} (${d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss")} UTC)` : result.toString();
}
}
export default ToUNIXTimestamp;
View on GitHub (pinned to 4290ea7539)
Solutions
- Set Units to one of the four supported values: Seconds (s), Milliseconds (ms), Microseconds (μs), or Nanoseconds (ns).
- If building the recipe programmatically, copy the exact option string including the unit abbreviation in parentheses.
- Regenerate the recipe through the UI to reset the option.
Example fix
// before: args[0] (Units) = "Seconds" -> not matched -> throws // after: args[0] (Units) = "Seconds (s)" -> matched, returns unix seconds
Defensive patterns
Strategy: validation
Validate before calling
const ALLOWED = ["Seconds (s)", "Milliseconds (ms)", "Microseconds (μs)", "Nanoseconds (ns)"];
if (!ALLOWED.includes(units)) throw new Error(`Unsupported unit: ${units}`); Type guard
const isSupportedUnit = u => ["Seconds (s)", "Milliseconds (ms)", "Microseconds (μs)", "Nanoseconds (ns)"].includes(u);
Try / catch
try { toUnixTimestamp(input, [units, treatAsUTC, showDateTime]); }
catch (e) { if (/Unrecognised unit/.test(e.message)) { units = "Seconds (s)"; } else throw e; } Prevention
- Always select the unit from the option list rather than typing it.
- When building recipes in code, copy the exact option string.
- Re-add the operation via the UI to reset the argument.
When it happens
Trigger: Passing a Units argument whose value is not one of the four supported option strings — e.g. via a programmatic recipe that sets an arbitrary string, or after editing the option list.
Common situations: Custom/programmatic recipe building that injects an invalid unit string; a locale-edited option label; a stale recipe referencing a renamed unit.
Related errors
- Byte length must be a positive integer
- L must be non-negative
- L too large (maximum length for ${args[2]} is ${255 * HashLe
- Unrecognised unit
- Invalid IV length: ${iv.length} bytes TEA uses an IV length
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/cb62366f5aad322a.
Report an issue: GitHub.