gchq/CyberChef · error · OperationError

Invalid length type

Error message

Invalid length type

What it means

Thrown by GenerateLoremIpsum.run() when lengthType is not one of Paragraphs, Sentences, Words, or Bytes. This is the fallback of the dispatch switch that selects the generator function. It is an enum-validation error on the lengthType argument.

Source

Thrown at src/core/operations/GenerateLoremIpsum.mjs:65

    /**
     * @param {string} input
     * @param {Object[]} args
     * @returns {string}
     */
    run(input, args) {
        const [length, lengthType] = args;
        checkLimits(lengthType, length);
        switch (lengthType) {
            case "Paragraphs":
                return GenerateParagraphs(length);
            case "Sentences":
                return GenerateSentences(length);
            case "Words":
                return GenerateWords(length);
            case "Bytes":
                return GenerateBytes(length);
            default:
                throw new OperationError("Invalid length type");

        }
    }

}

export default GenerateLoremIpsum;

/**
 * check combined validity of lengthType and length arguments
 * @param {string} lengthType
 * @param {number} length
 * @throws {OperationError}
 */
function checkLimits(lengthType, length) {
    if (length < 1) {
        throw new OperationError("Length must be greater than 0");
    }

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Set lengthType to one of: Paragraphs, Sentences, Words, Bytes.
  2. If building recipes in code, validate lengthType against the allowed set before invoking.

Example fix

// before
args = [50, "Lines"];
// after
args = [50, "Sentences"];
Defensive patterns

Strategy: type-guard

Validate before calling

const VALID_LENGTH_TYPES = ["Paragraphs", "Sentences", "Words", "Bytes"];
if (!VALID_LENGTH_TYPES.includes(lengthType)) {
  // reject before invoking
}

Type guard

function isLengthType(t) {
  return ["Paragraphs", "Sentences", "Words", "Bytes"].includes(t);
}

Prevention

When it happens

Trigger: Passing a lengthType value outside the four recognized strings — e.g. 'Characters', 'Lines', a typo, or undefined/null when building a recipe programmatically.

Common situations: Recipe built in code without setting lengthType, or a dropdown enum value changed between CyberChef versions.

Related errors


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