{"record":{"id":"2bd715d92396bd8e","repo":"karatelabs/karate","slug":"invalid-code-point","errorCode":null,"errorMessage":"Invalid code point ","messagePattern":"Invalid code point ","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsStringConstructor.java","lineNumber":74,"sourceCode":"    // Static methods\n\n    private Object fromCharCode(Object[] args) {\n        StringBuilder sb = new StringBuilder();\n        for (Object arg : args) {\n            if (arg instanceof Number num) {\n                sb.append((char) num.intValue());\n            }\n        }\n        return sb.toString();\n    }\n\n    private Object fromCodePoint(Object[] args) {\n        StringBuilder sb = new StringBuilder();\n        for (Object arg : args) {\n            if (arg instanceof Number num) {\n                int n = num.intValue();\n                if (n < 0 || n > 0x10FFFF) {\n                    throw JsErrorException.rangeError(\"Invalid code point \" + num);\n                }\n                sb.appendCodePoint(n);\n            }\n        }\n        return sb.toString();\n    }\n\n    // Spec §22.1.2.4 — String.raw(template, ...substitutions). Walks\n    // template.raw[k] for k in [0, length), interleaving substitutions[k] from\n    // the second arg onward. Coercion goes through the spec ToString helper so\n    // host objects with a JS toString return user-visible strings, and\n    // non-array-like raw values (length=NaN/0) fall through to the empty\n    // string per §22.1.2.4 step 6 / 8.\n    private Object raw(Context context, Object[] args) {\n        Object template = args.length > 0 ? args[0] : Terms.UNDEFINED;\n        Terms.requireObjectCoercible(template, \"String.raw\");\n        if (!(template instanceof ObjectLike templateObj)) {\n            throw JsErrorException.typeError(\"String.raw template must be an object\");","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsStringConstructor.java#L56-L92","documentation":"This RangeError is thrown by String.fromCodePoint when a numeric argument falls outside the valid Unicode code point range (0 to 0x10FFFF inclusive). Negative integers or values above the maximum code point cannot be encoded as a Unicode character, so the engine rejects them per spec (§22.1.2.2).","triggerScenarios":"Calling String.fromCodePoint(-1), String.fromCodePoint(0x110000), or any argument that coerces to a number outside 0..1114111. Note the source only appends arguments that are instanceof Number after the check — non-number args are silently skipped, so the error fires specifically for out-of-range numbers.","commonSituations":"Computing code points from data (e.g. parsing hex from user input) that was not range-checked; off-by-one when iterating Unicode ranges; decoding binary data where sentinel values like -1 appear; using values above 0x10FFFF for astral-plane math.","solutions":["Validate code points before calling: if (n < 0 || n > 0x10FFFF) skip or clamp","Mask sentinel values (e.g. stream read returning -1) to 0 or filter them out","Use String.fromCodePoint(...codes.filter(isValidCodePoint)) to sanitize input arrays"],"exampleFix":"// before\nconst ch = String.fromCodePoint(-1); // RangeError\n// after\nconst n = -1;\nconst ch = n >= 0 && n <= 0x10FFFF ? String.fromCodePoint(n) : '';","handlingStrategy":"validation","validationCode":"const isValidCodePoint = (n) => Number.isInteger(n) && n >= 0 && n <= 0x10FFFF;","typeGuard":null,"tryCatchPattern":"try { return String.fromCodePoint(...codes); } catch (e) { if (e.name === 'RangeError') return String.fromCodePoint(...codes.filter(isValidCodePoint)); throw e; }","preventionTips":["Filter code point arrays with a 0..0x10FFFF range check before fromCodePoint","Map stream-read sentinel values like -1 before treating them as code points","Surrogate-pair manual math should stay within 0..0x10FFFF; prefer String.fromCodePoint over manual charCode math"],"tags":["javascript","string","unicode","range-error"],"backgroundTag":"value-out-of-range","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}