{"record":{"id":"c73ffdd92bd7ebe0","repo":"gchq/CyberChef","slug":"length-must-be-greater-than-0","errorCode":null,"errorMessage":"Length must be greater than 0","messagePattern":"Length must be greater than 0","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/GenerateLoremIpsum.mjs","lineNumber":82,"sourceCode":"            default:\n                throw new OperationError(\"Invalid length type\");\n\n        }\n    }\n\n}\n\nexport default GenerateLoremIpsum;\n\n/**\n * check combined validity of lengthType and length arguments\n * @param {string} lengthType\n * @param {number} length\n * @throws {OperationError}\n */\nfunction checkLimits(lengthType, length) {\n    if (length < 1) {\n        throw new OperationError(\"Length must be greater than 0\");\n    }\n\n    switch (lengthType) {\n        case \"Paragraphs\":\n        case \"Sentences\":\n        case \"Words\":\n            if (length > maxLoremWords) {\n                throw new OperationError(\"Length must be less than \" + maxLoremWords);\n            }\n            break;\n        case \"Bytes\":\n            if (length > maxLoremCharacters) {\n                throw new OperationError(\"Length must be less than \" + maxLoremCharacters);\n            }\n            break;\n        default:\n            throw new OperationError(\"Invalid length type\");\n    }","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/GenerateLoremIpsum.mjs#L64-L100","documentation":"Thrown by GenerateLoremIpsum's checkLimits() helper when the length argument is less than 1. This is a lower-bound validation that applies to all length types before the per-type maximum check. Fractional or zero/negative lengths are rejected.","triggerScenarios":"Passing length = 0, a negative number, or a value that coerces to < 1 (e.g. NaN from a non-numeric ingredient).","commonSituations":"Default/empty length field, or a UI control that allows zero.","solutions":["Set length to a positive integer (>= 1).","Validate that the length ingredient is a number and not NaN before invoking."],"exampleFix":"// before\nargs = [0, \"Words\"];\n// after\nargs = [10, \"Words\"];","handlingStrategy":"validation","validationCode":"if (!Number.isInteger(length) || length < 1) {\n  // reject before invoking; length must be a positive integer\n}","typeGuard":"function isPositiveLength(n) {\n  return Number.isInteger(n) && n >= 1;\n}","tryCatchPattern":null,"preventionTips":["Default the length field to a sensible positive integer.","Reject zero, negative, or NaN lengths at the input boundary."],"tags":["lorem-ipsum","argument-validation","numeric","user-input"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}