stride3d/stride · error · SyntaxErrorException

While scanning a plain scalar, find unexpected ':'.

Error message

While scanning a plain scalar, find unexpected ':'.

What it means

Thrown by the YAML Scanner while scanning a plain (unquoted) scalar when a ':' appears in a position where it would be ambiguous or illegal — specifically inside flow context ({}, []) when the colon is not followed by a blank/break, or a colon elsewhere in a spot that terminates the scalar incorrectly. YAML only allows ':' in plain scalars under strict conditions, and this input violates them.

Solutions

  1. Quote the offending scalar with double or single quotes so ':' is allowed anywhere inside it.
  2. Add a space after the colon if it was meant as a mapping separator, e.g. {a: b} instead of {a:b}.
  3. Rewrite the flow collection as block-style mappings, which have more lenient colon handling.
  4. Validate the document with a YAML parser before feeding it to the application.

Example fix

// before
urls: [http://example.com, http://other.org]
// after
urls: ["http://example.com", "http://other.org"]
Defensive patterns

Strategy: try-catch

Validate before calling

// Detect 'x:y' inside flow context before parsing
bool HasColonInFlowScalar(string yaml) =>
    System.Text.RegularExpressions.Regex.IsMatch(yaml, "\\{[^}]*[a-zA-Z0-9]:[^\\s}]");

Try / catch

try
{
    var obj = new Deserializer().Deserialize<ObjectT>(yamlReader);
}
catch (SyntaxErrorException ex)
{
    Log.Error(ex, "Unexpected ':' in plain scalar at line {Line}, col {Col}", ex.Start.Line, ex.Start.Column);
    throw;
}

Prevention

When it happens

Trigger: Parsing YAML containing a plain scalar with 'key:value' (no space after colon) inside a flow collection, e.g. {a:b: c}, or any plain scalar where a ':' is followed by a non-space in flow context.

Common situations: Users writing JSON-ish '{url:http://example.com}' in YAML; URLs containing ':' inside flow sequences without quoting; values copied from JSON that rely on JSON's looser colon rules.

Related errors


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

Appendix: source

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

                {
                    break;
                }

                // Check for a comment.

                if (analyzer.Check('#'))
                {
                    break;
                }

                // Consume non-blank characters.
                while (!analyzer.IsBlankOrBreakOrZero())
                {
                    // Check for 'x:x' in the flow context. TODO: Fix the test "spec-08-13".

                    if (flowLevel > 0 && analyzer.Check(':') && !analyzer.IsBlankOrBreakOrZero(1))
                    {
                        throw new SyntaxErrorException(start, mark, "While scanning a plain scalar, find unexpected ':'.");
                    }

                    // Check for indicators that may end a plain scalar.

                    if ((analyzer.Check(':') && analyzer.IsBlankOrBreakOrZero(1)) || (flowLevel > 0 && analyzer.Check(",:?[]{}")))
                    {
                        break;
                    }

                    // Check if we need to join whitespaces and breaks.

                    if (hasLeadingBlanks || whitespaces.Length > 0)
                    {
                        if (hasLeadingBlanks)
                        {
                            // Do we need to fold line breaks?

                            if (StartsWith(leadingBreak, '\n'))

View on GitHub (pinned to 96fad776d2)