Humanizr/Humanizer · error · InvalidOperationException
Unexpected indentation on line {line.LineNumber}.
Error message
Unexpected indentation on line {line.LineNumber}. What it means
Within a YAML sequence block, every item line must sit at exactly the sequence's indent level. If a line's indent is greater than the sequence indent (but not less, which would simply end the sequence), the parser cannot assign it to any item and rejects it as structurally ambiguous.
Source
Thrown at src/Humanizer.SourceGenerators/Common/LocaleYamlCatalog.cs:1440
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)
{
break;
}
if (line.Indent != indent)
{
throw new InvalidOperationException($"Unexpected indentation on line {line.LineNumber}.");
}
if (!IsSequenceItem(line.Content))
{
break;
}
var remainder = line.Content.Length == 1
? string.Empty
: line.Content.Substring(2).TrimStart();
index++;
if (remainder.Length == 0)
{
items.Add(ParseBlock(lines, ref index, indent + 2, rejectDuplicateKeys));
continue;
}
View on GitHub (pinned to ffc2b77c0f)
Solutions
- Align all sequence item lines ('- ') to the same even indent column.
- Ensure continuation content under a sequence item is indented exactly 2 spaces deeper than the item marker.
- Use the line number in the message to locate and fix the misaligned line.
Example fix
# before — inconsistent item indent
headings:
full:
- January
- February
# after — uniform item indent
headings:
full:
- January
- February Defensive patterns
Strategy: validation
Validate before calling
# A standard YAML parser catches inconsistent sequence indentation.
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 indentation error: {e}') Prevention
- Align all sequence item markers ('- ') to the same column within a block.
- Indent continuation content exactly 2 spaces deeper than the item marker.
- Run a YAML linter to catch inconsistent indentation before the source generator runs.
When it happens
Trigger: A sequence item or its continuation content is indented inconsistently — for example items at 2 spaces but one item's content at 5 spaces, or a sibling mapping key placed inside a sequence scope at the wrong depth.
Common situations: Indentation drift within multi-line sequence items; mixed indent widths; pasting content from a differently-indented source into a sequence block.
Related errors
- Unsupported indentation on line {lineNumber + 1}. Locale YAM
- Phrase '{path}' must be a scalar string.
- Locale YAML root must be a mapping.
- Unexpected end of YAML document.
- Locale '{localeCode}.{path}' defines duplicate numeric minut
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/0e008fdb1ae1c33b.
Report an issue: GitHub.