gchq/CyberChef · error · OperationError

Length must be greater than 0

Error message

Length must be greater than 0

What it means

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.

Source

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

            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");
    }

    switch (lengthType) {
        case "Paragraphs":
        case "Sentences":
        case "Words":
            if (length > maxLoremWords) {
                throw new OperationError("Length must be less than " + maxLoremWords);
            }
            break;
        case "Bytes":
            if (length > maxLoremCharacters) {
                throw new OperationError("Length must be less than " + maxLoremCharacters);
            }
            break;
        default:
            throw new OperationError("Invalid length type");
    }

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Set length to a positive integer (>= 1).
  2. Validate that the length ingredient is a number and not NaN before invoking.

Example fix

// before
args = [0, "Words"];
// after
args = [10, "Words"];
Defensive patterns

Strategy: validation

Validate before calling

if (!Number.isInteger(length) || length < 1) {
  // reject before invoking; length must be a positive integer
}

Type guard

function isPositiveLength(n) {
  return Number.isInteger(n) && n >= 1;
}

Prevention

When it happens

Trigger: Passing length = 0, a negative number, or a value that coerces to < 1 (e.g. NaN from a non-numeric ingredient).

Common situations: Default/empty length field, or a UI control that allows zero.

Related errors


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