stride3d/stride · error · SyntaxErrorException

Mapping keys are not allowed in this context.

Error message

Mapping keys are not allowed in this context.

What it means

YAML scanner error in FetchKey: a KEY token ('?...' or an implicit mapping key) appears in block context where simple keys are not currently allowed — typically a mapping key appearing after a value on the same line or inside a sequence item, i.e. a key placed where the grammar forbids it.

Solutions

  1. Move the key to its own line at the correct indentation level
  2. Fix block/sequence structure so keys only appear inside mappings
  3. Replace '? ' explicit-key syntax misuse with plain mapping syntax

Example fix

// before
a: 1 ? b: 2
// after
? [a, b]
: value
Defensive patterns

Strategy: validation

Try / catch

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

Prevention

When it happens

Trigger: A '? key' construct appearing after a scalar on the same line or inside a context where the scanner has already consumed a node, e.g. 'a: 1 ? b'.

Common situations: Using explicit complex-key syntax ('? {a: 1}\n: value') in the wrong position, or stray '?' characters left from editing nested mappings.

Related errors


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

Appendix: source

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

            // Create the BLOCK-ENTRY token and append it to the queue.

            tokens.Enqueue(new BlockEntry(start, mark));
        }

        /// <summary>
        /// Produce the KEY token.
        /// </summary>
        private void FetchKey()
        {
            // In the block context, additional checks are required.

            if (flowLevel == 0)
            {
                // Check if we are allowed to start a new key (not nessesary simple).

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

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

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

            // Reset any potential simple keys on the current flow level.

            RemoveSimpleKey();

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

            simpleKeyAllowed = flowLevel == 0;

            // Consume the token.

            Mark start = mark;

View on GitHub (pinned to 96fad776d2)