{"record":{"id":"0249e2f8ca891966","repo":"gchq/CyberChef","slug":"unrecognised-unit","errorCode":null,"errorMessage":"Unrecognised unit","messagePattern":"Unrecognised unit","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/FromUNIXTimestamp.mjs","lineNumber":86,"sourceCode":"        const units = args[0];\n        let d;\n\n        input = parseFloat(input);\n\n        if (units === \"Seconds (s)\") {\n            d = moment.unix(input);\n            return d.tz(\"UTC\").format(\"ddd D MMMM YYYY HH:mm:ss\") + \" UTC\";\n        } else if (units === \"Milliseconds (ms)\") {\n            d = moment(input);\n            return d.tz(\"UTC\").format(\"ddd D MMMM YYYY HH:mm:ss.SSS\") + \" UTC\";\n        } else if (units === \"Microseconds (μs)\") {\n            d = moment(input / 1000);\n            return d.tz(\"UTC\").format(\"ddd D MMMM YYYY HH:mm:ss.SSS\") + \" UTC\";\n        } else if (units === \"Nanoseconds (ns)\") {\n            d = moment(input / 1000000);\n            return d.tz(\"UTC\").format(\"ddd D MMMM YYYY HH:mm:ss.SSS\") + \" UTC\";\n        } else {\n            throw new OperationError(\"Unrecognised unit\");\n        }\n    }\n\n}\n\nexport default FromUNIXTimestamp;\n","sourceCodeStart":68,"sourceCodeEnd":93,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/FromUNIXTimestamp.mjs#L68-L93","documentation":"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.","triggerScenarios":"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.","commonSituations":"Programmatic invocation supplying a free-text unit; recipe migration that dropped the canonical option value; edge case where args[0] is undefined.","solutions":["Use one of the canonical unit strings: 'Seconds (s)', 'Milliseconds (ms)', 'Microseconds (μs)', 'Nanoseconds (ns)'.","If building args in code, source the unit from the UNITS constant rather than hardcoding.","Validate args[0] against the allowed set before invoking."],"exampleFix":"// before: invalid unit string\nfromUnix.run(1609459200, ['Minutes']) // throws\n// after: canonical unit\nfromUnix.run(1609459200, ['Seconds (s)'])","handlingStrategy":"validation","validationCode":"import { UNITS } from \"../lib/DateTime.mjs\";\nif (!UNITS.includes(args[0])) {\n  // set args[0] to a canonical unit; do not call fromUnix.run()\n}","typeGuard":"function isValidTimestampUnit(u) {\n  return ['Seconds (s)', 'Milliseconds (ms)', 'Microseconds (μs)', 'Nanoseconds (ns)'].includes(u);\n}","tryCatchPattern":"try {\n  fromUnix.run(input, args);\n} catch (e) {\n  if (e.type === 'OperationError' && e.message === 'Unrecognised unit') {\n    // fix args[0] to a canonical unit string from UNITS\n  } else throw e;\n}","preventionTips":["Source the Units value from the UNITS constant, not free text.","Validate args[0] against the allowed set before invoking.","Avoid hand-editing recipe files' unit option."],"tags":["datetime","unix-timestamp","argument-validation","config"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}