denoland/deno · error
Unexpected termination of string.
Error message
Unexpected termination of string.
What it means
While scanning a parenthesized pattern, cli/lsp/path_to_regex.rs:156 pushes a backslash then requires one more character for the escape pair. If the input ends right after that backslash, chars.next() returns None and the lexer reports "Unexpected termination of string." — the regex pattern was cut off mid-escape.
Source
Thrown at cli/lsp/path_to_regex.rs:156
if chars.peek() == Some(&'?') {
return Err(anyhow!(
"Pattern cannot start with \"?\" at {}.",
index + 1
));
}
loop {
let next_char = chars.peek();
if next_char.is_none() {
break;
}
if next_char == Some(&'\\') {
pattern.push(chars.next().unwrap());
pattern.push(
chars
.next()
.ok_or_else(|| anyhow!("Unexpected termination of string."))?,
);
continue;
}
if next_char == Some(&')') {
count -= 1;
if count == 0 {
chars.next();
break;
}
} else if next_char == Some(&'(') {
count += 1;
pattern.push(chars.next().unwrap());
if chars.peek() != Some(&'?') {
return Err(anyhow!(
"Capturing groups are not allowed at {}.",
index + pattern.len()
));
}View on GitHub (pinned to 89f33cbef2)
Solutions
- Close the pattern properly and escape backslashes in pairs: "/x/:pkg([a-z\\.]+)"
- In JSON source, write "\\\\" for each literal backslash you want in the regex
- Validate the schema with a path-to-regex parser before shipping
Example fix
// before
{ "schema": "/x/:pkg([a-z+\\" }
// after
{ "schema": "/x/:pkg([a-z.]+)" } Defensive patterns
Strategy: validation
Validate before calling
function endsWithDanglingEscapeInsidePattern(s: string): boolean {
const open = s.lastIndexOf("(");
if (open === -1) return false;
const tail = s.slice(open);
return !tail.includes(")") && endsWithDanglingEscape(tail);
} Prevention
- Write escape pairs atomically: \\. not a lone \
- Close every parenthesis before ending the string; then check for dangling escapes
- Keep patterns short so truncation is obvious in review
When it happens
Trigger: A schema like "/x/:pkg([a-z+\\" where the pattern's closing ')' is missing and the string ends on a lone backslash; truncated config.json payloads.
Common situations: Under-escaped JSON (a planned "\\\\" becoming "\\"), string truncation from template length limits, or hand-merging schema edits that deleted the tail of the pattern.
Related errors
- Unexpected end of string at {}.
- Missing parameter name at {}
- Pattern cannot start with "?" at {}.
- Capturing groups are not allowed at {}.
- Unbalanced pattern at {}.
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/0ae89bac5102bc4e.
Report an issue: GitHub.