stride3d/stride · error · SyntaxErrorException

While scanning a directive, did not find expected comment…

Error message

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

What it means

After a %YAML or %TAG directive and its value, the scanner requires the rest of the line to be a comment or a line break. If trailing non-comment text follows the directive, it throws this SyntaxErrorException.

Solutions

  1. Remove any text after the directive value on that line
  2. Add a comment with '#' if an annotation is desired ('%YAML 1.2 # note')
  3. Ensure the directive line ends with a newline

Example fix

// before
%YAML 1.2 extra junk
---
// after
%YAML 1.2
---
Defensive patterns

Strategy: validation

Validate before calling

// Directive lines must end right after their value
foreach (var line in yamlText.Split('\n')) { var t = line.TrimEnd(); if (t.StartsWith("%YAML")) { var parts = t.Split(' ', System.StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 2) throw new FormatException("Trailing text after %YAML directive"); } }

Try / catch

catch (SyntaxErrorException ex) { throw new ConfigFormatException($"Malformed directive line near {ex.Start.Line}"); }

Prevention

When it happens

Trigger: Text after a directive on the same line, e.g. '%YAML 1.2 extra' or '%TAG ! tag:example.com,2000: foo'.

Common situations: Hand-written directives with stray trailing words, or shell-style inline arguments appended to a %YAML line.

Related errors


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

Appendix: source

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

            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 directive, did not find expected comment or line break.");
            }

            // Eat a line break.

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

            return directive;
        }

        /// <summary>
        /// Produce the DOCUMENT-START or DOCUMENT-END token.
        /// </summary>
        private void FetchDocumentIndicator(bool isStartToken)
        {
            // Reset the indentation level.

View on GitHub (pinned to 96fad776d2)