stride3d/stride · error · SyntaxErrorException

While scanning a quoted scalar, find unexpected document…

Error message

While scanning a quoted scalar, find unexpected document indicator.

What it means

While scanning a single- or double-quoted scalar, the Scanner checks at the start of each line whether a YAML document indicator (--- or ...) begins there. A quoted scalar must not span a document boundary, so encountering '---' or '...' at line start inside an unterminated quote throws this SyntaxErrorException.

Solutions

  1. Find and close the unterminated quote that precedes the '---'/'...' line (the scanner's start Mark points at the quoted scalar's beginning).
  2. Ensure document separators '---'/'...' appear only at line start outside any quoted scalar.
  3. If the content legitimately starts a line with '---', use a block scalar (| or >) instead of a quoted scalar.
  4. Quote content containing dashes with double quotes and keep the quote on one line, or escape appropriately.
  5. Split multi-document streams and parse each document separately to isolate the offending quote.

Example fix

// before (unclosed quote swallows the document marker)
title: 'unclosed
---
next: value

// after
title: 'closed'
---
next: value
Defensive patterns

Strategy: try-catch

Validate before calling

static bool QuotesLookBalanced(string yaml)
{
    int singles = 0, doubles = 0;
    foreach (char c in yaml)
    {
        if (c == '\'') singles ^= 1;
        else if (c == '"') doubles ^= 1;
    }
    return singles == 0 && doubles == 0; // rough check, ignores escapes
}

Try / catch

try
{
    yamlStream.Load(reader);
}
catch (YamlException ex)
{
    throw new FormatException($"Unterminated quote (ran into a document marker) starting near {ex.Start.Line}:{ex.Start.Column}", ex);
}

Prevention

When it happens

Trigger: An unclosed quote earlier in the document causes subsequent '---'/'...' document markers to be consumed as part of the quoted scalar; e.g. "title: 'unclosed\n---\nnext: doc". Thrown during tokenization of multi-document streams with an unbalanced quote in an earlier document.

Common situations: Multi-document YAML files (--- separated) where a quote in one document was never closed, string content containing three dashes at line start without proper quoting, and concatenating documents that lost a closing quote.

Related errors


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

Appendix: source

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

            // Eat the left quote.

            Mark start = mark;
            Mark end = mark;

            Skip();

            // Consume the content of the quoted scalar.
            scanScalarValue.Clear();
            scanScalarWhitespaces.Clear();
            scanScalarLeadingBreak.Clear();
            scanScalarTrailingBreaks.Clear();
            for (;;)
            {
                // Check that there are no document indicators at the beginning of the line.

                if (IsDocumentIndicator())
                {
                    throw new SyntaxErrorException(start, mark, "While scanning a quoted scalar, find unexpected document indicator.");
                }

                // Check for EOF.

                if (analyzer.IsZero())
                {
                    throw new SyntaxErrorException(start, mark, "While scanning a quoted scalar, find unexpected end of stream.");
                }

                // Consume non-blank characters.

                bool hasLeadingBlanks = false;

                while (!analyzer.IsBlankOrBreakOrZero())
                {
                    // Check for an escaped single quote.

                    if (isSingleQuoted && analyzer.Check('\'', 0) && analyzer.Check('\'', 1))

View on GitHub (pinned to 96fad776d2)