denoland/deno · error

Pattern cannot start with "?" at {}.

Error message

Pattern cannot start with "?" at {}.

What it means

cli/lsp/path_to_regex.rs:140 lexes the parenthesized regex part of a placeholder. If the first character inside '(' is '?', it errors with "Pattern cannot start with \"?\"" — a leading '?' would make the whole custom pattern optional, which the token model forbids (optionality belongs on the placeholder, via '{name?}', not the regex).

Source

Thrown at cli/lsp/path_to_regex.rs:140

          }
        }
        if name.is_empty() {
          return Err(anyhow!("Missing parameter name at {}", index));
        }
        let name_len = name.len();
        tokens.push(LexToken {
          token_type: TokenType::Name,
          index,
          value: name,
        });
        index += 1 + name_len;
      }
      Some('(') => {
        let mut count = 1;
        let mut pattern = String::new();

        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;

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Remove the leading '?': "/x/:pkg([a-z]+)"
  2. Wrap flag-style constructs in a non-capturing group: "/x/:pkg((?i)[a-z]+)" — the outer group now starts with '(' so it passes
  3. For optional segments use the placeholder syntax "/x/{name?}" instead of a '?' in the pattern

Example fix

// before
{ "schema": "/x/:pkg(?i)" }

// after
{ "schema": "/x/:pkg((?i)[a-z]+)" }
Defensive patterns

Strategy: validation

Validate before calling

const m = schema.match(/\((\?)/); // '(' immediately followed by '?'
if (m) throw new Error(`pattern starts with '?' near index ${m.index}`);

Prevention

When it happens

Trigger: A schema placeholder whose inline pattern begins with '?', e.g. "/x/:pkg(?i)" or "/x/:pkg(?[a-z]+)"; attempts to inline regex flags like (?i) directly after the colon-name.

Common situations: Registry authors pasting PCRE with flags into the pattern slot; trying to express optional matching via '?' at pattern start instead of the placeholder's optional marker.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/bf71cdb7abd970b6. Report an issue: GitHub.