gchq/CyberChef · error · OperationError

${err}

Error message

${err}

What it means

Catch-all OperationError thrown by 'VarInt Encode' for any failure inside the try block other than the explicit negative check. The most common cause is BigInt(input) throwing SyntaxError because the input string is not a valid integer literal (letters, decimals, empty string, or trailing characters).

Source

Thrown at src/core/operations/VarIntEncode.mjs:52

     * @returns {byteArray}
     */
    run(input, args) {
        try {
            if (typeof BigInt === "function") {
                let value = BigInt(input);
                if (value < 0) throw new OperationError("Negative values cannot be represented as VarInt");
                const result = [];
                while (value >= 0x80) {
                    result.push(Number(value & BigInt(0x7f)) | 0x80);
                    value >>= BigInt(7);
                }
                result.push(Number(value));
                return result;
            } else {
                return Protobuf.varIntEncode(Number(input));
            }
        } catch (err) {
            throw new OperationError(err);
        }
    }

}

export default VarIntEncode;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Provide a string that is a valid integer literal (digits only, optional leading sign).
  2. Round/truncate decimals to integers before encoding.
  3. Inspect the wrapped err for the precise parse failure.

Example fix

// before
varIntEncode("3.14");
// after
varIntEncode("3");
Defensive patterns

Strategy: validation

Validate before calling

if (!/^-?\d+$/.test(String(input).trim())) {
  throw new Error(`VarInt Encode expects an integer string, got '${input}'`);
}

Type guard

function isIntegerString(s) { return /^-?\d+$/.test(String(s).trim()); }

Try / catch

try { return varIntEncode(input); }
catch (err) { throw new Error(`VarInt encode failed: ${err.message}`); }

Prevention

When it happens

Trigger: Input that BigInt() cannot parse: a floating-point string like '3.14', a non-numeric string, an empty string, or a value with whitespace/symbols. Also wraps errors from the Protobuf fallback path when BigInt is unavailable.

Common situations: Piping text or hex data into VarInt Encode without first converting to a decimal integer, or feeding decimal fractions.

Related errors


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