{"record":{"id":"bdabeb607a09cdb1","repo":"karatelabs/karate","slug":"invalid-binary-literal","errorCode":null,"errorMessage":"invalid binary literal","messagePattern":"invalid binary literal","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsLexer.java","lineNumber":480,"sourceCode":"            }\n            // Rare path: BigInt suffix — `0xff_ffn` is valid\n            if (!isAtEnd() && peek() == 'n') {\n                advance();\n                return BIGINT;\n            }\n            return NUMBER;\n        }\n\n        // Binary number (0b / 0B)\n        if (c == '0' && (peek(1) == 'b' || peek(1) == 'B')) {\n            advance(); // 0\n            advance(); // b\n            int binStart = pos;\n            while (!isAtEnd() && (peek() == '0' || peek() == '1')) {\n                advance();\n            }\n            if (pos == binStart) {\n                throw new ParserException(\"invalid binary literal\");\n            }\n            if (!isAtEnd() && peek() == '_') {\n                scanBinaryDigitsWithSeparators();\n            }\n            if (!isAtEnd() && peek() == 'n') {\n                advance();\n                return BIGINT;\n            }\n            return NUMBER;\n        }\n\n        // Octal number (0o / 0O)\n        if (c == '0' && (peek(1) == 'o' || peek(1) == 'O')) {\n            advance(); // 0\n            advance(); // o\n            int octStart = pos;\n            while (!isAtEnd() && peek() >= '0' && peek() <= '7') {\n                advance();","sourceCodeStart":462,"sourceCodeEnd":498,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsLexer.java#L462-L498","documentation":"Karate's embedded JS lexer throws this when it sees a `0b` prefix but no binary digit (0 or 1) follows. The lexer requires at least one valid binary digit after the `0b`/`0B` marker, matching the ECMAScript numeric literal grammar. It is a ParserException raised during tokenization, before parsing.","triggerScenarios":"Writing JS in a Karate script with a malformed binary literal such as `0b`, `0b2`, `0b_1`, or `0B` — the `0b` is immediately followed by a non-binary character or end of token.","commonSituations":"Typo in a bitwise operation or numeric constant inside embedded JS expressions (`karate.js`, `eval` blocks, `* assert` steps); hand-editing constants and dropping a digit; copy-pasted code where digits after `0b` were lost.","solutions":["Add at least one binary digit after the `0b` prefix (e.g. `0b1010` instead of `0b`).","Remove the `0b` prefix if a decimal value was intended (e.g. `0b` -> `0`).","Check the character immediately after `0b` — only `0` and `1` are valid; `2`-`9` or `_` start the literal incorrectly.","Escape or move the text out of JS context if `0b` is not meant to be a literal (e.g. inside a string)."],"exampleFix":"// before\n* def x = 0b\n// after\n* def x = 0b1010","handlingStrategy":"validation","validationCode":"// validate before passing to karate eval\nfunction isValidJsNumberLiteral(s) {\n  return /^0[bB][01]+n?$/.test(s.trim());\n}\nif (!isValidJsNumberLiteral(expr)) throw new Error('bad binary literal: ' + expr);","typeGuard":null,"tryCatchPattern":"try {\n  def x = eval(expr);\n} catch (e) {\n  if (e.message && e.message.indexOf('invalid binary literal') >= 0) {\n    karate.log('malformed binary literal, fix 0b usage: ' + expr);\n  }\n  throw e;\n}","preventionTips":["Only use 0b prefix when you actually mean binary; else use decimal.","Verify digits after 0b are only 0 or 1.","Keep numeric constants in shared JS/feature files under review for typos.","Escape 0b sequences that are textual data as strings."],"tags":["javascript","lexer","numeric-literal"],"backgroundTag":"invalid-argument-value","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}