{"record":{"id":"5bd150b5ac5778b2","repo":"stride3d/stride","slug":"expected-0-got-1-at-line-2-character-3","errorCode":null,"errorMessage":"Expected '{0}', got '{1}' (at line {2}, character {3}).","messagePattern":"Expected '(.+?)', got '(.+?)' \\(at line (.+?), character (.+?)\\)\\.","errorType":"exception","errorClass":"YamlException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/EventReader.cs","lineNumber":93,"sourceCode":"        /// </summary>\n        /// <value>The parser.</value>\n        public IParser Parser { get { return parser; } }\n\n        public int CurrentDepth { get { return currentDepth; } }\n\n        /// <summary>\n        /// Ensures that the current event is of the specified type, returns it and moves to the next event.\n        /// </summary>\n        /// <typeparam name=\"T\">Type of the <see cref=\"Event\"/>.</typeparam>\n        /// <returns>Returns the current event.</returns>\n        /// <exception cref=\"YamlException\">If the current event is not of the specified type.</exception>\n        public T Expect<T>() where T : Event\n        {\n            var yamlEvent = Allow<T>();\n            if (yamlEvent == null)\n            {\n                // TODO: Throw a better exception\n                throw new YamlException(\n                    parser.Current.Start,\n                    parser.Current.End,\n                    string.Format(\n                        CultureInfo.InvariantCulture,\n                        \"Expected '{0}', got '{1}' (at line {2}, character {3}).\",\n                        typeof(T).Name,\n                        parser.Current.GetType().Name,\n                        parser.Current.Start.Line,\n                        parser.Current.Start.Column\n                        )\n                    );\n            }\n            return yamlEvent;\n        }\n\n        /// <summary>\n        /// Moves to the next event.\n        /// </summary>","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/EventReader.cs#L75-L111","documentation":"EventReader.Expect<T>() peeks the parser's next event and throws this YamlException (with start/end marks) when the next event is not of the requested type T. It is the typed reader's way of enforcing a strict event sequence while consuming a YAML stream.","triggerScenarios":"Calling reader.Expect<ScalarEvent>() (or Expect<DocumentStartEvent>, etc.) when the parser's current event is a different type; calling Expect after the stream already ended; misjudging document structure (e.g. expecting a mapping where the file has a scalar).","commonSituations":"Custom parsers walking YAML manually with EventReader; config files whose shape differs from what the reader expects (list instead of map); reading past the last document so the next event is StreamEnd.","solutions":["Inspect the message's 'got X at line/character' part and fix the YAML or the Expect call to match the actual event type","Use Allow<T>() (returns null) instead of Expect<T>() when the event type is optional","Call reader.Peek()/Allow for a union of acceptable types before narrowing","Validate the input document's structure before parsing it with a strict Expect sequence"],"exampleFix":"// before\nvar scalar = reader.Expect<ScalarEvent>();\n// after\nvar scalar = reader.Allow<ScalarEvent>();\nif (scalar == null) {\n  var peeked = reader.Peek();\n  throw new FormatException($\"Unexpected event {peeked?.Type} at {peeked?.Start}\");\n}","handlingStrategy":"try-catch","validationCode":"var peeked = reader.Peek();\nif (!(peeked is ScalarEvent)) throw new FormatException($\"Expected scalar, got {peeked?.GetType().Name} at {peeked?.Start}\");","typeGuard":null,"tryCatchPattern":"try { var e = reader.Expect<ScalarEvent>(); }\ncatch (YamlException ex) { var m = ex.Start; Console.WriteLine($\"YAML structure mismatch at line {m.Line}, col {m.Column}: {ex.Message}\"); }","preventionTips":["Prefer Allow<T>() when the event type is optional","Dump the offending YAML around the reported line/column","Don't call Expect after the stream has ended","Validate document shape with a schema before strict event-walking"],"tags":["yaml","parser","event-reader"],"backgroundTag":"yaml-parse-error","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}