stride3d/stride · error · YamlException

Unable to parse input

Error message

Unable to parse input

What it means

TagTypeSerializer.ReadYaml throws this when it peeks the next parsing event and gets null, meaning the reader has no event available to process. Because there is no event, no start/end location can be attached to the YamlException.

Solutions

  1. Ensure the YAML input is a non-empty, well-formed document before deserializing.
  2. Check file/stream length and read the text first to fail early on empty input.
  3. Validate the YAML parses (e.g. with a parser round-trip) before handing it to this serializer.
  4. Fix the upstream producer that truncated the stream.

Example fix

// before
using var reader = new StreamReader(path); // file may be empty
var obj = serializer.Deserialize(reader);
// after
var text = File.ReadAllText(path);
if (string.IsNullOrWhiteSpace(text)) throw new InvalidDataException($"YAML file '{path}' is empty");
var obj = serializer.Deserialize(new StringReader(text));
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(yamlInput)) throw new InvalidDataException("YAML input is empty; nothing to deserialize");

Try / catch

try { return serializer.Deserialize(reader); } catch (YamlException ex) when (ex.Message == "Unable to parse input") { throw new InvalidDataException("YAML stream was empty or exhausted before a node was read", ex); }

Prevention

When it happens

Trigger: Calling ReadYaml on an exhausted/empty event stream; feeding an empty document to the deserializer; a corrupted or truncated YAML stream where the reader reaches EOF before a node event.

Common situations: Empty config files passed to a deserializer; truncated YAML from a failed download or interrupted write; calling the serializer pipeline on a reader positioned past the end of input.

Understand the failure class

Related errors


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

Appendix: source

Thrown at sources/core/Stride.Core.Yaml/Serialization/Serializers/TagTypeSerializer.cs:62

// SOFTWARE.

using System;
using System.Collections.Generic;
using Stride.Core.Reflection;
using Stride.Core.Yaml.Events;

namespace Stride.Core.Yaml.Serialization.Serializers
{
    internal class TagTypeSerializer : ChainedSerializer
    {
        public override object ReadYaml(ref ObjectContext objectContext)
        {
            var parsingEvent = objectContext.Reader.Peek<ParsingEvent>();
            // Can this happen here?
            if (parsingEvent == null)
            {
                // TODO check how to put a location in this case?
                throw new YamlException("Unable to parse input");
            }

            var node = parsingEvent as NodeEvent;
            if (node == null)
            {
                throw new YamlException(parsingEvent.Start, parsingEvent.End, $"Unexpected parsing event found [{parsingEvent}]. Expecting Scalar, Mapping or Sequence");
            }

            var type = objectContext.Descriptor != null ? objectContext.Descriptor.Type : null;

            // Tries to get a Type from the TagTypes
            Type typeFromTag = null;
            if (!string.IsNullOrEmpty(node.Tag))
            {
                bool remapped;
                typeFromTag = objectContext.SerializerContext.TypeFromTag(node.Tag, out remapped);
                if (typeFromTag == null)
                {

View on GitHub (pinned to 96fad776d2)