Humanizr/Humanizer · error · InvalidOperationException

Unexpected end of YAML document.

Error message

Unexpected end of YAML document.

What it means

The parser's ParseBlock entry point expects at least one line at the current indent level to begin a sequence or mapping. If the line index has already consumed all lines when a block is required — typically because a parent node implied children that are absent — it throws rather than returning an empty or ambiguous node.

Source

Thrown at src/Humanizer.SourceGenerators/Common/LocaleYamlCatalog.cs:1416

                if (c == '#' && !inSingleQuote && !inDoubleQuote)
                {
                    break;
                }

                builder.Append(c);
            }

            return builder.ToString().TrimEnd();
        }

        static SimpleYamlValue ParseBlock(
            IReadOnlyList<LineInfo> lines,
            ref int index,
            int indent,
            bool rejectDuplicateKeys)
        {
            return index >= lines.Count
                ? throw new InvalidOperationException("Unexpected end of YAML document.")
                : IsSequenceItem(lines[index].Content)
                ? ParseSequence(lines, ref index, indent, rejectDuplicateKeys)
                : ParseMapping(lines, ref index, indent, rejectDuplicateKeys);
        }

        static SimpleYamlSequence ParseSequence(
            IReadOnlyList<LineInfo> lines,
            ref int index,
            int indent,
            bool rejectDuplicateKeys)
        {
            var items = ImmutableArray.CreateBuilder<SimpleYamlValue>();

            while (index < lines.Count)
            {
                var line = lines[index];
                if (line.Indent < indent)
                {

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Inspect the end of the file for a key or sequence marker with no value below it.
  2. Add the expected child content or remove the orphaned parent key.
  3. Run a YAML linter on the file to locate the structural break.

Example fix

# before — key with no value at EOF
formatter:
  engine: default
calendar:

# after — provide value or remove key
formatter:
  engine: default
Defensive patterns

Strategy: validation

Validate before calling

# A standard YAML parser will flag truncated/dangling structures.
import yaml, pathlib
locales_dir = pathlib.Path('src/Humanizer/Locales')
for f in locales_dir.rglob('*.yml'):
    try:
        yaml.safe_load(f.read_text())
    except yaml.YAMLError as e:
        print(f'{f.name}: YAML parse error (possible dangling key): {e}')

Prevention

When it happens

Trigger: A locale YAML structure implies a nested block that is missing: for example a sequence item '- ' with no following content at deeper indent, or a mapping key followed by end-of-file with no value.

Common situations: Truncating a locale file mid-structure; deleting child lines but leaving the parent key; a merge conflict artifact leaving a dangling parent key.

Related errors


AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13). Data as JSON: /api/errors/9dbaf2284465d9e0. Report an issue: GitHub.