gchq/CyberChef · error · OperationError
'Drop every' must be a positive integer.
Error message
'Drop every' must be a positive integer.
What it means
Thrown in DropNthBytes.run when the first argument n ('Drop every') fails parseInt(n,10) !== n || n <= 0. parseInt(n,10) !== n is the classic integer check (false for NaN and any non-integer). With n <= 0 it enforces a strictly positive integer. The arg defaults to 4, so this fires only for an out-of-range user or programmatic value.
Source
Thrown at src/core/operations/DropNthBytes.mjs:57
name: "Apply to each line",
type: "boolean",
value: false
}
];
}
/**
* @param {byteArray} input
* @param {Object[]} args
* @returns {byteArray}
*/
run(input, args) {
const n = args[0];
const start = args[1];
const eachLine = args[2];
if (parseInt(n, 10) !== n || n <= 0) {
throw new OperationError("'Drop every' must be a positive integer.");
}
if (parseInt(start, 10) !== start || start < 0) {
throw new OperationError("'Starting at' must be a positive or zero integer.");
}
let offset = 0;
const output = [];
for (let i = 0; i < input.length; i++) {
if (eachLine && input[i] === 0x0a) {
output.push(0x0a);
offset = i + 1;
} else if (i - offset < start || (i - (start + offset)) % n !== 0) {
output.push(input[i]);
}
}
return output;
}View on GitHub (pinned to 4290ea7539)
Solutions
- Set 'Drop every' to a whole number >= 1 (default 4).
- If building the recipe programmatically, coerce with Math.max(1, Math.floor(n)) first.
- Per AGENTS.md, move this constraint into the Ingredient args metadata (min value / integer) so validateIngredients() rejects it before run().
- Validate imported recipe JSON before loading.
Example fix
// before const args = [0, 0, false]; // throws // after const args = [Math.max(1, Math.floor(n)), 0, false];
Defensive patterns
Strategy: validation
Validate before calling
function dropEvery(n) {
if (!Number.isInteger(n) || n <= 0) throw new RangeError("Drop every must be a positive integer");
return n;
}
const safeN = dropEvery(args[0]); Type guard
const isPositiveInt = (v) => Number.isInteger(v) && v > 0;
Prevention
- Coerce computed n with Math.max(1, Math.floor(n)) before passing.
- Prefer declaring integer/min constraints in the Ingredient args metadata so validateIngredients() rejects bad values pre-run.
- Validate imported recipe JSON before loading.
When it happens
Trigger: The 'Drop every' field receives 0, a negative number, a fraction like 2.5, NaN, or a non-numeric string. Common via imported recipe JSON with a bad value, a cleared UI field that coerces oddly, or the Node API passing an unguarded computed value.
Common situations: Hand-edited recipe JSON setting Drop every to 0 or a float; programmatic use passing a float multiplier; UI field left blank and coerced to 0.
Related errors
- 'Starting at' must be a positive or zero integer.
- Rotor ${i} must be provided.
- The values of a and b can only be integers.
- Incorrect number of samples.
- Incorrect number of samples.
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/cf9f2124c79ad4dd.
Report an issue: GitHub.