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

  1. Set Units to one of the four supported values: Seconds (s), Milliseconds (ms), Microseconds (μs), or Nanoseconds (ns).
  2. If building the recipe programmatically, copy the exact option string including the unit abbreviation in parentheses.
  3. 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

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


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