{"record":{"id":"a35b329af3dfc42c","repo":"gchq/CyberChef","slug":"err-a35b32","errorCode":null,"errorMessage":"${err}","messagePattern":"\\$\\{err\\}","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/VarIntEncode.mjs","lineNumber":52,"sourceCode":"     * @returns {byteArray}\n     */\n    run(input, args) {\n        try {\n            if (typeof BigInt === \"function\") {\n                let value = BigInt(input);\n                if (value < 0) throw new OperationError(\"Negative values cannot be represented as VarInt\");\n                const result = [];\n                while (value >= 0x80) {\n                    result.push(Number(value & BigInt(0x7f)) | 0x80);\n                    value >>= BigInt(7);\n                }\n                result.push(Number(value));\n                return result;\n            } else {\n                return Protobuf.varIntEncode(Number(input));\n            }\n        } catch (err) {\n            throw new OperationError(err);\n        }\n    }\n\n}\n\nexport default VarIntEncode;\n","sourceCodeStart":34,"sourceCodeEnd":59,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/VarIntEncode.mjs#L34-L59","documentation":"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).","triggerScenarios":"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.","commonSituations":"Piping text or hex data into VarInt Encode without first converting to a decimal integer, or feeding decimal fractions.","solutions":["Provide a string that is a valid integer literal (digits only, optional leading sign).","Round/truncate decimals to integers before encoding.","Inspect the wrapped err for the precise parse failure."],"exampleFix":"// before\nvarIntEncode(\"3.14\");\n// after\nvarIntEncode(\"3\");","handlingStrategy":"validation","validationCode":"if (!/^-?\\d+$/.test(String(input).trim())) {\n  throw new Error(`VarInt Encode expects an integer string, got '${input}'`);\n}","typeGuard":"function isIntegerString(s) { return /^-?\\d+$/.test(String(s).trim()); }","tryCatchPattern":"try { return varIntEncode(input); }\ncatch (err) { throw new Error(`VarInt encode failed: ${err.message}`); }","preventionTips":["Round/truncate decimals to integers first.","Pipe only numeric integer data into VarInt Encode."],"tags":["protobuf","varint","validation","input-type","runtime"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}