karatelabs/karate · error · ParserException
missing exponent digits
Error message
missing exponent digits
What it means
A numeric literal contains an exponent marker (`e` or `E`, optionally with sign) but no exponent digits follow. ECMAScript requires at least one digit after the exponent marker, so `1e`, `1.e+`, or `1e-` are rejected at tokenization time.
Solutions
- Append the missing exponent digits (`1e` -> `1e10`, `1.e+` -> `1.5e+3`).
- Remove the trailing `e`/`e+`/`e-` if the exponent was not intended.
- If the value is dynamic, build the number in two parts: `1 * math.pow(10, n)` instead of string-forming `1e${n}`.
Example fix
// before * def x = 1e // after * def x = 1e10
Defensive patterns
Strategy: validation
Validate before calling
// exponent marker must be followed by at least one digit
if (/[eE][+-]?$/.test(expr)) throw new Error('exponent missing digits: ' + expr); Try / catch
try {
def x = eval(expr);
} catch (e) {
if (e.message && e.message.indexOf('missing exponent digits') >= 0) {
karate.log('incomplete scientific notation: ' + expr);
}
throw e;
} Prevention
- Never build numeric literals via string interpolation with possibly-empty parts; compute with math instead.
- Check for truncation after copy-paste of scientific notation.
- Validate dynamic expressions with a regex before eval.
When it happens
Trigger: Truncated scientific notation in embedded JS: `1e`, `2.5e+`, `1E-` — caused by incomplete typing, string interpolation cutting off the number, or a template like `1e${x}` where x is empty.
Common situations: Dynamic numeric construction via string concatenation where the exponent variable is empty; copy-paste truncation; accidental insertion of whitespace after `e` inside what should be one number token.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- invalid numeric separator
- invalid binary literal
- invalid octal literal
- invalid escape sequence in template literal: \
- invalid escape sequence in template literal: \0
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/fb735deb82c34080.
Report an issue: GitHub.
Appendix: source
Thrown at karate-js/src/main/java/io/karatelabs/parser/JsLexer.java:568
char p = peek();
if (p == 'e' || p == 'E') {
isInteger = false;
advance();
if (peek() == '+' || peek() == '-') {
advance();
}
int expDigitsStart = pos;
while (!isAtEnd() && isDigit(peek())) {
advance();
}
if (!isAtEnd() && peek() == '_') {
if (pos == expDigitsStart) {
throw new ParserException("invalid numeric separator");
}
scanDigitsWithSeparators();
} else if (pos == expDigitsStart) {
// `1e`, `1.e+` — the exponent marker requires at least one digit
throw new ParserException("missing exponent digits");
}
}
// Rare path: BigInt suffix — only valid on integer literals
if (isInteger && !isAtEnd() && peek() == 'n') {
advance();
return BIGINT;
}
return NUMBER;
}
// Slow path: number contained at least one `_` separator. Spec rules:
// - `_` must appear between two digits (no leading, trailing, or doubled)
// - the first `_` we see has already been validated (preceding char is a digit)
private void scanDigitsWithSeparators() {
while (!isAtEnd() && peek() == '_') {
advance(); // consume `_`View on GitHub (pinned to a22eb90246)