gchq/CyberChef · error · OperationError

Unrecognised unit

Error message

Unrecognised unit

What it means

Thrown by From UNIX Timestamp when the Units argument matches none of the known options (Seconds, Milliseconds, Microseconds, Nanoseconds). The operation branches on exact string equality for each unit; any other value falls through to the else clause. This is an argument/configuration error, typically only reachable via a custom/invalid unit string.

Source

Thrown at src/core/operations/FromUNIXTimestamp.mjs:86

        const units = args[0];
        let d;

        input = parseFloat(input);

        if (units === "Seconds (s)") {
            d = moment.unix(input);
            return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss") + " UTC";
        } else if (units === "Milliseconds (ms)") {
            d = moment(input);
            return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss.SSS") + " UTC";
        } else if (units === "Microseconds (μs)") {
            d = moment(input / 1000);
            return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss.SSS") + " UTC";
        } else if (units === "Nanoseconds (ns)") {
            d = moment(input / 1000000);
            return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss.SSS") + " UTC";
        } else {
            throw new OperationError("Unrecognised unit");
        }
    }

}

export default FromUNIXTimestamp;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Use one of the canonical unit strings: 'Seconds (s)', 'Milliseconds (ms)', 'Microseconds (μs)', 'Nanoseconds (ns)'.
  2. If building args in code, source the unit from the UNITS constant rather than hardcoding.
  3. Validate args[0] against the allowed set before invoking.

Example fix

// before: invalid unit string
fromUnix.run(1609459200, ['Minutes']) // throws
// after: canonical unit
fromUnix.run(1609459200, ['Seconds (s)'])
Defensive patterns

Strategy: validation

Validate before calling

import { UNITS } from "../lib/DateTime.mjs";
if (!UNITS.includes(args[0])) {
  // set args[0] to a canonical unit; do not call fromUnix.run()
}

Type guard

function isValidTimestampUnit(u) {
  return ['Seconds (s)', 'Milliseconds (ms)', 'Microseconds (μs)', 'Nanoseconds (ns)'].includes(u);
}

Try / catch

try {
  fromUnix.run(input, args);
} catch (e) {
  if (e.type === 'OperationError' && e.message === 'Unrecognised unit') {
    // fix args[0] to a canonical unit string from UNITS
  } else throw e;
}

Prevention

When it happens

Trigger: Passing a Units value not in the UNITS list (e.g. 'Minutes', a typo, or a localized string); constructing the args array programmatically with an unvalidated unit; a recipe file edited by hand with an invalid option.

Common situations: Programmatic invocation supplying a free-text unit; recipe migration that dropped the canonical option value; edge case where args[0] is undefined.

Related errors


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