stride3d/stride · error · SyntaxErrorException

While scanning a block scalar, did not find expected…

Error message

While scanning a block scalar, did not find expected comment or line break.

What it means

A block scalar's first line may only contain the header (|/> with optional indicators) followed by optional spaces and a comment, then a line break. If ScanBlockScalar finds any other non-break, non-comment character after the header (or trailing content after the header comment), it throws this SyntaxErrorException.

Solutions

  1. Put the block content on the lines following the header: 'text: |' then newline then content.
  2. Remove any stray text after '|' or '>' on the header line; only an optional comment (starting with #) is allowed before the line break.
  3. Ensure a '#' comment after the header is separated by at least one space and nothing follows the comment.
  4. Check for lost newlines from editors or transports that may have joined the header line with content.
  5. Run a YAML linter to detect invalid characters after block scalar headers.

Example fix

// before (content on header line)
text: | first line inline
  more

// after
text: |
  first line
  more
Defensive patterns

Strategy: validation

Validate before calling

static bool BlockHeadersEndCleanly(string yaml)
{
    // content must not follow | or > (optionally with indicators) on the same line
    return !System.Text.RegularExpressions.Regex.IsMatch(yaml, @"[|>][0-9+-]*[ 	]+[^# 	\\r\\n]");
}

Try / catch

try
{
    var obj = deserializer.Deserialize<T>(input);
}
catch (YamlException ex)
{
    throw new FormatException($"Invalid text after block scalar header at {ex.Start.Line}:{ex.Start.Column}", ex);
}

Prevention

When it happens

Trigger: Content on the same line as the block scalar header, e.g. 'text: | extra content' or '|#comment junk' where text follows the comment, or a missing line break right after '|' or '>'. Thrown while tokenizing the block scalar header.

Common situations: Appending notes or defaults after '|' in hand-edited configs, template engines leaving placeholder text on the header line, and copy-paste merging the header line with the first content line.

Related errors


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

Appendix: source

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

            while (analyzer.IsBlank())
            {
                Skip();
            }

            if (analyzer.Check('#'))
            {
                while (!analyzer.IsBreakOrZero())
                {
                    Skip();
                }
            }

            // Check if we are at the end of the line.

            if (!analyzer.IsBreakOrZero())
            {
                throw new SyntaxErrorException(start, mark, "While scanning a block scalar, did not find expected comment or line break.");
            }

            // Eat a line break.

            if (analyzer.IsBreak())
            {
                SkipLine();
            }

            Mark end = mark;

            // Set the intendation level if it was specified.

            if (increment != 0)
            {
                currentIndent = indent >= 0 ? indent + increment : increment;
            }

View on GitHub (pinned to 96fad776d2)