gchq/CyberChef · error · OperationError

Unknown granularity value: ${granularity}

Error message

Unknown granularity value: ${granularity}

What it means

Thrown by GetTime when the granularity argument is not one of the four recognized units: Nanoseconds (ns), Microseconds (μs), Milliseconds (ms), or Seconds (s). The switch selects the multiplier to convert the current epoch-millis time; an unknown unit is rejected rather than defaulted.

Source

Thrown at src/core/operations/GetTime.mjs:57

     * @param {string} input
     * @param {Object[]} args
     * @returns {number}
     */
    run(input, args) {
        const nowMs = (performance.timeOrigin + performance.now()),
            granularity = args[0];

        switch (granularity) {
            case "Nanoseconds (ns)":
                return Math.round(nowMs * 1000 * 1000);
            case "Microseconds (μs)":
                return Math.round(nowMs * 1000);
            case "Milliseconds (ms)":
                return Math.round(nowMs);
            case "Seconds (s)":
                return Math.round(nowMs / 1000);
            default:
                throw new OperationError("Unknown granularity value: " + granularity);
        }
    }

}

export default GetTime;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Set granularity to one of: 'Nanoseconds (ns)', 'Microseconds (μs)', 'Milliseconds (ms)', 'Seconds (s)'.
  2. If building recipes in code, validate granularity against the exact supported strings.

Example fix

// before
args = ["Minutes"];
// after
args = ["Milliseconds (ms)"];
Defensive patterns

Strategy: type-guard

Validate before calling

const VALID_GRANULARITIES = [
  "Nanoseconds (ns)",
  "Microseconds (\u03bcs)",
  "Milliseconds (ms)",
  "Seconds (s)"
];
if (!VALID_GRANULARITIES.includes(granularity)) {
  // reject before invoking
}

Type guard

function isTimeGranularity(g) {
  return [
    "Nanoseconds (ns)",
    "Microseconds (\u03bcs)",
    "Milliseconds (ms)",
    "Seconds (s)"
  ].includes(g);
}

Prevention

When it happens

Trigger: Passing a granularity string outside the four recognized labels, including misspellings, alternate casing, or values like 'Minutes'/'Hours' which are not supported.

Common situations: Recipe built in code with an unsupported granularity, or a localized label mismatch from the UI.

Related errors


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