Humanizr/Humanizer · error · InvalidOperationException

Unsupported indentation on line {lineNumber + 1}. Locale YAM

Error message

Unsupported indentation on line {lineNumber + 1}. Locale YAML uses 2-space indentation.

What it means

The locale YAML parser is intentionally minimal and only supports even-width (2-space-multiple) indentation. It counts leading spaces and rejects any line whose indent count is odd, because the parser's indent arithmetic relies on multiples of two to infer nesting depth.

Source

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

            var lines = text.Split(["\r\n", "\n"], StringSplitOptions.None);

            for (var lineNumber = 0; lineNumber < lines.Length; lineNumber++)
            {
                var rawLine = StripComment(lines[lineNumber]);
                if (string.IsNullOrWhiteSpace(rawLine))
                {
                    continue;
                }

                var indent = 0;
                while (indent < rawLine.Length && rawLine[indent] == ' ')
                {
                    indent++;
                }

                if ((indent & 1) != 0)
                {
                    throw new InvalidOperationException($"Unsupported indentation on line {lineNumber + 1}. Locale YAML uses 2-space indentation.");
                }

                result.Add(new LineInfo(indent, rawLine.Trim(), lineNumber + 1));
            }

            return result;
        }

        static string StripComment(string line)
        {
            var builder = new StringBuilder(line.Length);
            var inSingleQuote = false;
            var inDoubleQuote = false;

            for (var i = 0; i < line.Length; i++)
            {
                var c = line[i];
                if (c == '\'' && !inDoubleQuote)

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Replace tabs with spaces and ensure every indent level is exactly 2 spaces.
  2. Check the line number in the message and fix the leading whitespace to an even count.
  3. Configure your editor to insert spaces for tabs with a 2-space indent width for locale YAML files.

Example fix

# before — 3-space indent (odd)
formatter:
   engine: default

# after — 2-space indent (even)
formatter:
  engine: default
Defensive patterns

Strategy: validation

Validate before calling

# Check every non-blank line for odd indentation or tabs.
import pathlib
locales_dir = pathlib.Path('src/Humanizer/Locales')
for f in locales_dir.rglob('*.yml'):
    for i, line in enumerate(f.read_text().splitlines(), 1):
        stripped = line.lstrip(' ')
        if stripped == line.lstrip():
            continue  # no leading spaces
        indent = len(line) - len(stripped)
        if '\t' in line[:indent + 1]:
            print(f'{f.name}:{i}: tab character in indentation')
        if indent % 2 != 0:
            print(f'{f.name}:{i}: odd indentation ({indent} spaces)')

Prevention

When it happens

Trigger: Any non-blank locale YAML line has an odd number of leading spaces (1, 3, 5, ...) or uses tab characters (tabs are not counted as space indentation and shift the count). The {lineNumber+1} placeholder names the offending line.

Common situations: Mixing tabs and spaces; using 4-space indentation in some lines and 2 in others; editor auto-indent inserting an odd space count; pasting content from a source with different indent width.

Related errors


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