{"record":{"id":"3854fc576e49c33a","repo":"stride3d/stride","slug":"expected-document-end","errorCode":null,"errorMessage":"Expected DOCUMENT-END.","messagePattern":"Expected DOCUMENT-END\\.","errorType":"exception","errorClass":"YamlException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Emitter.cs","lineNumber":1563,"sourceCode":"        private void EmitDocumentEnd(ParsingEvent evt)\n        {\n            DocumentEnd documentEnd = evt as DocumentEnd;\n            if (documentEnd != null)\n            {\n                WriteIndent();\n                if (!documentEnd.IsImplicit)\n                {\n                    WriteIndicator(\"...\", true, false, false);\n                    WriteIndent();\n                }\n\n                state = EmitterState.YAML_EMIT_DOCUMENT_START_STATE;\n\n                tagDirectives.Clear();\n            }\n            else\n            {\n                throw new YamlException(\"Expected DOCUMENT-END.\");\n            }\n        }\n\n        /// <summary>\n        /// \n        /// Expect a flow item node.\n        /// </summary>\n        private void EmitFlowSequenceItem(ParsingEvent evt, bool isFirst)\n        {\n            if (isFirst)\n            {\n                WriteIndicator(\"[\", true, true, false);\n                IncreaseIndent(true, false);\n                ++flowLevel;\n            }\n\n            if (evt is SequenceEnd)\n            {","sourceCodeStart":1545,"sourceCodeEnd":1581,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Emitter.cs#L1545-L1581","documentation":"The emitter's state machine was in a document context and expected a DOCUMENT-END event, but received something else. Emitter.EmitDocumentEndContent throws when the current event is not DocumentEnd, meaning documents were not properly terminated before starting new content.","triggerScenarios":"Emitting a second DocumentStart or node event while the emitter still awaits DocumentEnd for the previous document; feeding StreamEnd without closing the open document.","commonSituations":"Multi-document emission loops that forget to call Emit(new DocumentEnd(...)) per document; exception-recovery paths that skip the end event; merging event streams from multiple sources.","solutions":["Emit a DocumentEnd event after each document's node before starting the next","Ensure every Emit(DocumentStart) has a matching Emit(DocumentEnd)","Restart emission with a new Emitter after an error instead of continuing the broken state machine","Audit the event-producing loop for missing end events"],"exampleFix":"// before\nemitter.Emit(docStart2); // previous document still open\n// after\nemitter.Emit(new DocumentEnd(true, null, null));\nemitter.Emit(docStart2);","handlingStrategy":"try-catch","validationCode":"// track expected state before each Emit\nbool expectDocEnd = documentOpen;\nif (expectDocEnd && evt.Type != EventType.YAML_DOCUMENT_END_EVENT) throw new InvalidOperationException(\"Emit DocumentEnd first\");","typeGuard":null,"tryCatchPattern":"try { emitter.Emit(evt); }\ncatch (YamlException ex) when (ex.Message.Contains(\"Expected DOCUMENT-END\")) { /* emit DocumentEnd, then re-queue the event */ }","preventionTips":["Pair every DocumentStart with a DocumentEnd in the same code path","Use try/finally to guarantee DocumentEnd on failures","Avoid interleaving events from multiple documents into one emitter"],"tags":["yaml","emitter","state-machine"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}