stride3d/stride · error · SyntaxErrorException

Mapping values are not allowed in this context.

Error message

Mapping values are not allowed in this context.

What it means

A ':' mapping value indicator was found where a complex value is not allowed. This occurs when ':' follows a scalar in block context without that scalar having been a valid simple key (simpleKeyAllowed is false).

Solutions

  1. Quote the scalar containing the colon: "http://example.com"
  2. Remove the extra ':' if two key/value pairs were meant to be nested — put the nested mapping on the next line with indentation
  3. Check the reported line for stray ':' characters

Example fix

// before
key: value: other
// after
key:
  nested: other
Defensive patterns

Strategy: validation

Validate before calling

// Flag unquoted scalars with multiple colons in block context
var lines = yamlText.Split('\n'); foreach (var l in lines) { var t = l.Trim(); if (t.StartsWith("#")) continue; var first = t.IndexOf(": "); if (first >= 0 && t.IndexOf(": ", first + 1) >= 0 && !t.Contains("\"") && !t.Contains("'")) throw new FormatException("Unquoted colon in value: " + l); }

Type guard

bool NeedsQuoting(string s) => s.Contains(": ") || s.TrimEnd().EndsWith(":");

Try / catch

catch (SyntaxErrorException ex) { throw new ConfigFormatException($"':' misplaced near {ex.Start.Line}:{ex.Start.Column}"); }

Prevention

When it happens

Trigger: A colon appearing after content on the same line where the scanner cannot start a new mapping, e.g. 'a b: c' where 'a b' wasn't recorded as a possible simple key, or ':' after an already-completed value like 'key: v1: v2'.

Common situations: Two colons on one line ('key: value: other'), or colons inside unquoted scalars in block context.

Related errors


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

Appendix: source

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

                simpleKey.IsPossible = false;

                // A simple key cannot follow another simple key.

                simpleKeyAllowed = false;
            }
            else
            {
                // The ':' indicator follows a complex key.

                // In the block context, extra checks are required.

                if (flowLevel == 0)
                {
                    // Check if we are allowed to start a complex value.

                    if (!simpleKeyAllowed)
                    {
                        throw new SyntaxErrorException(mark, mark, "Mapping values are not allowed in this context.");
                    }

                    // Add the BLOCK-MAPPING-START token if needed.

                    RollIndent(mark.Column, -1, false, mark);
                }

                // Simple keys after ':' are allowed in the block context.

                simpleKeyAllowed = flowLevel == 0;
            }

            // Consume the token.

            Mark start = mark;
            Skip();

            // Create the VALUE token and append it to the queue.

View on GitHub (pinned to 96fad776d2)