gchq/CyberChef · error · OperationError
'Take every' must be a positive integer.
Error message
'Take every' must be a positive integer.
What it means
Take Nth Bytes requires the 'Take every' argument (n) to be a positive integer. The guard `parseInt(n,10) !== n || n <= 0` rejects non-integers and values <= 0 before the sampling loop runs, because a non-positive or fractional stride is meaningless for byte selection.
Source
Thrown at src/core/operations/TakeNthBytes.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("'Take 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
- Enter a positive integer such as 1, 2, or 5 for 'Take every'.
- Use 1 to keep every byte from the start offset onward.
- Confirm no decimal point or negative sign is present in the field.
Example fix
// before: args[0] (Take every) = 0 -> throws // after: args[0] (Take every) = 2 -> keeps every 2nd byte
Defensive patterns
Strategy: type-guard
Validate before calling
const n = args[0];
if (!(Number.isInteger(n) && n > 0)) {
throw new Error("'Take every' must be a positive integer");
} Type guard
const isPositiveInt = v => Number.isInteger(v) && v > 0;
Try / catch
try { takeNthBytes(input, n, start, eachLine); }
catch (e) { if (/Take every/.test(e.message)) { /* set n to a positive int */ } else throw e; } Prevention
- Validate stride with Number.isInteger before calling.
- Default the field to 1 so it is always valid.
- Reject fractional or negative input in your UI layer.
When it happens
Trigger: Passing a non-integer (e.g. 2.5) or a non-positive value (0, -1) for the 'Take every' argument. Also triggered by NaN or string values that fail the parseInt identity check.
Common situations: Leaving the field blank (defaults to an invalid value), entering 0 meaning 'take nothing', or pasting a decimal where an integer is expected.
Related errors
- 'Starting at' must be a positive or zero integer.
- Width must be a positive integer
- ${this.name} must be an integer.
- Byte length must be a positive integer
- L must be non-negative
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/774f798d18e31637.
Report an issue: GitHub.