nodejs/node · error

Cannot do u8'...'\n

Error message

Cannot do u8'...'\n

What it means

escapesrc explicitly rejects the u8'x' form (UTF-8 narrow character literal). It supports u8"..." strings but not the single-character u8'...' literal, which the comment at fixAt documents as unsupported. The tool returns an error rather than emit incorrect output.

Source

Thrown at deps/icu-small/source/tools/escapesrc/escapesrc.cpp:233

  pos++; // past 'u'

  bool utf8 = false;
  
  if(linestr[pos] == '8') { // u8"
    utf8 = true;
    pos++;
  }
  
  char quote = linestr[pos];

  if(quote != '\'' && quote != '\"') {
    fprintf(stderr, "Quote is '%c' - not sure what to do.\n", quote);
    return true;
  }

  if(quote == '\'' && utf8) {
    fprintf(stderr, "Cannot do u8'...'\n");
    return true;
  }

  pos ++;

  //printf("u%c…%c\n", quote, quote);

  for(; pos < linestr.size(); pos++) {
    if(linestr[pos] == quote) {
      if(utf8) {
        return fixu8(linestr, origpos, pos); // fix u8"..."
      } else {
        return false; // end of quote
      }
    }
    if(linestr[pos] == '\\') {
      pos++;
      if(linestr[pos] == quote) continue; // quoted quote

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Rewrite u8'x' literals as plain 'x' (char) or as a u8"x" single-character string, which escapesrc does support.
  2. If a multi-byte UTF-8 character is required, use u8"\uXXXX" string form instead of a char literal.
  3. Pre-process or post-process the source to convert u8'...' forms before running escapesrc.

Example fix

// before
char c = u8'A';

// after
char c = 'A';
// or, if a UTF-8 string is intended:
const char* c = u8"A";
Defensive patterns

Strategy: validation

Validate before calling

// pre-scan: rewrite u8'x' forms to supported forms before escapesrc
import re
src2 = re.sub(r"u8'(.)'", lambda m: f"u8\"{m.group(1)}\"" if ord(m.group(1)) > 127 else f"'{m.group(1)}'", src)

Prevention

When it happens

Trigger: A source line contains a u8-prefixed single-quoted character literal, e.g. u8'A' or u8'\n'. fixAt detects (quote == '\'' && utf8) and fails the line.

Common situations: Modern C++17+ code using u8 char literals; porting code that previously used char literals to UTF-8 literals for consistency; code generated by a tool that emits u8'...' uniformly.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/845e62e89ddaa253. Report an issue: GitHub.