stride3d/stride · error · SyntaxErrorException

While parsing a quoted scalar, find invalid Unicode…

Error message

While parsing a quoted scalar, find invalid Unicode character escape code.

What it means

Thrown by the YAML Scanner when a Unicode escape sequence inside a quoted scalar decodes to a value that is not a valid scalar Unicode character: a surrogate code point (0xD800-0xDFFF) or anything above the Unicode maximum (0x10FFFF). The escape is syntactically well-formed hex but semantically cannot represent a character, so the scanner rejects it.

Solutions

  1. Replace the lone surrogate escape with the real code point, e.g. "\uD83D\uDE00" becomes "\U0001F600" (single escape for the combined character).
  2. Clamp or correct the escape value so it is <= 0x10FFFF and not in the D800-DFFF surrogate range.
  3. Put the actual character in the file (UTF-8 encoded YAML) instead of an escape sequence.
  4. Fix the upstream encoder that emitted surrogate-pair escapes into YAML.

Example fix

// before
emoji: "\uD83D\uDE00"
// after
emoji: "\U0001F600"
Defensive patterns

Strategy: validation

Validate before calling

static bool IsValidUnicodeEscapeValue(uint v) => v <= 0x10FFFF && (v < 0xD800 || v > 0xDFFF);

Try / catch

try
{
    var obj = Deserializer.FromText(yaml);
}
catch (SyntaxErrorException ex)
{
    Log.Error(ex, "Invalid Unicode escape code at {Start}", ex.Start);
    throw new YamlConfigException("YAML contains surrogate or out-of-range escape", ex);
}

Prevention

When it happens

Trigger: Parsing a YAML document whose quoted scalar contains escapes such as "\uD800" (lone surrogate, common when JSON-style surrogate pairs were copied verbatim) or "\u00110000" (value above 0x10FFFF).

Common situations: Converting JSON/JavaScript data to YAML where astral characters were encoded as surrogate pairs instead of a single code point; generated escape strings from buggy encoders; hand-written \U escapes with values past the Unicode range.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/8355eba146f8b6d5. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Yaml/Scanner.cs:1688

                        {
                            uint character = 0;

                            // Scan the character value.

                            for (int k = 0; k < codeLength; ++k)
                            {
                                if (!analyzer.IsHex(k))
                                {
                                    throw new SyntaxErrorException(start, mark, "While parsing a quoted scalar, did not find expected hexdecimal number.");
                                }
                                character = (uint) ((character << 4) + analyzer.AsHex(k));
                            }

                            // Check the value and write the character.

                            if ((character >= 0xD800 && character <= 0xDFFF) || character > 0x10FFFF)
                            {
                                throw new SyntaxErrorException(start, mark, "While parsing a quoted scalar, find invalid Unicode character escape code.");
                            }

                            scanScalarValue.Append((char) character);

                            // Advance the pointer.

                            for (int k = 0; k < codeLength; ++k)
                            {
                                Skip();
                            }
                        }
                    }
                    else
                    {
                        // It is a non-escaped non-blank character.

                        scanScalarValue.Append(ReadCurrentCharacter());
                    }

View on GitHub (pinned to 96fad776d2)