{"record":{"id":"972735dbe83a9e6b","repo":"gchq/CyberChef","slug":"unknown-granularity-value-granularity","errorCode":null,"errorMessage":"Unknown granularity value: ${granularity}","messagePattern":"Unknown granularity value: (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/GetTime.mjs","lineNumber":57,"sourceCode":"     * @param {string} input\n     * @param {Object[]} args\n     * @returns {number}\n     */\n    run(input, args) {\n        const nowMs = (performance.timeOrigin + performance.now()),\n            granularity = args[0];\n\n        switch (granularity) {\n            case \"Nanoseconds (ns)\":\n                return Math.round(nowMs * 1000 * 1000);\n            case \"Microseconds (μs)\":\n                return Math.round(nowMs * 1000);\n            case \"Milliseconds (ms)\":\n                return Math.round(nowMs);\n            case \"Seconds (s)\":\n                return Math.round(nowMs / 1000);\n            default:\n                throw new OperationError(\"Unknown granularity value: \" + granularity);\n        }\n    }\n\n}\n\nexport default GetTime;\n","sourceCodeStart":39,"sourceCodeEnd":64,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/GetTime.mjs#L39-L64","documentation":"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.","triggerScenarios":"Passing a granularity string outside the four recognized labels, including misspellings, alternate casing, or values like 'Minutes'/'Hours' which are not supported.","commonSituations":"Recipe built in code with an unsupported granularity, or a localized label mismatch from the UI.","solutions":["Set granularity to one of: 'Nanoseconds (ns)', 'Microseconds (μs)', 'Milliseconds (ms)', 'Seconds (s)'.","If building recipes in code, validate granularity against the exact supported strings."],"exampleFix":"// before\nargs = [\"Minutes\"];\n// after\nargs = [\"Milliseconds (ms)\"];","handlingStrategy":"type-guard","validationCode":"const VALID_GRANULARITIES = [\n  \"Nanoseconds (ns)\",\n  \"Microseconds (\\u03bcs)\",\n  \"Milliseconds (ms)\",\n  \"Seconds (s)\"\n];\nif (!VALID_GRANULARITIES.includes(granularity)) {\n  // reject before invoking\n}","typeGuard":"function isTimeGranularity(g) {\n  return [\n    \"Nanoseconds (ns)\",\n    \"Microseconds (\\u03bcs)\",\n    \"Milliseconds (ms)\",\n    \"Seconds (s)\"\n  ].includes(g);\n}","tryCatchPattern":null,"preventionTips":["Restrict the granularity control to the four known labels (note the μ character in Microseconds).","Match the exact label strings, including units in parentheses."],"tags":["time","argument-validation","enum","user-input"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}