stride3d/stride · error · YamlException

Expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS…

Error message

Expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS, got {0}

What it means

EmitterStateYamlException thrown by EmitterStateTransition when the event fed to the emitter is not a scalar, sequence-start, mapping-start, or alias. The emitter's state machine expected a node event but received some other event type (e.g. stream/document events out of order).

Solutions

  1. Emit events in valid YAML grammar order (StreamStart, DocumentStart, node events, DocumentEnd, StreamEnd)
  2. Create a fresh Emitter instance instead of reusing one after a failure or completed document
  3. Log/validate the event sequence before Emit and ensure only node events appear inside a document
  4. Check the event type string in the message to find which producer emitted the wrong event

Example fix

// before
emitter.Emit(new DocumentEnd(true, null, null)); // inside a node context
// after
emitter.Emit(new Scalar(null, null, "value", ScalarStyle.Plain, true, false, null, null));
Defensive patterns

Strategy: try-catch

Validate before calling

var allowed = new[]{ EventType.YAML_SCALAR_EVENT, EventType.YAML_SEQUENCE_START_EVENT, EventType.YAML_MAPPING_START_EVENT, EventType.YAML_ALIAS_EVENT };
bool ok = allowed.Contains(evt.Type);

Try / catch

try { emitter.Emit(evt); }
catch (YamlException ex) when (ex.Message.StartsWith("Expected SCALAR")) { /* restart emission with a fresh Emitter and a valid event order */ }

Prevention

When it happens

Trigger: Calling Emit with an event type outside {Scalar, SequenceStart, MappingStart, AnchorAlias} at a point where a node is expected — typically reusing an Emitter after a document ended, or feeding events in an order that violates the YAML event grammar.

Common situations: Custom emitters or event translators that skip DocumentStart/DocumentEnd pairing; retrying Emit after an earlier failure left the state machine mid-document; buggy event generators streaming events out of order.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at sources/core/Stride.Core.Yaml/Emitter.cs:908

            {
                case EventType.YAML_ALIAS_EVENT:
                    EmitAlias();
                    break;

                case EventType.YAML_SCALAR_EVENT:
                    EmitScalar(evt);
                    break;

                case EventType.YAML_SEQUENCE_START_EVENT:
                    EmitSequenceStart(evt);
                    break;

                case EventType.YAML_MAPPING_START_EVENT:
                    EmitMappingStart(evt);
                    break;

                default:
                    throw new YamlException(string.Format("Expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS, got {0}", eventType));
            }
        }

        /// <summary>
        /// Expect SEQUENCE-START.
        /// </summary>
        private void EmitSequenceStart(ParsingEvent evt)
        {
            ProcessAnchor();
            ProcessTag();

            SequenceStart sequenceStart = (SequenceStart) evt;

            if (flowLevel != 0 || isCanonical || sequenceStart.Style == DataStyle.Compact || CheckEmptySequence())
            {
                state = EmitterState.YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE;
            }
            else

View on GitHub (pinned to 96fad776d2)