Humanizr/Humanizer · error · InvalidOperationException
Inflection lexemes must be mappings.
Error message
Inflection lexemes must be mappings.
What it means
Each item in the 'lexemes:' sequence must itself be a YAML mapping (an object with keys like id, pos, countability, forms, sources). ParseLexemes throws when a list item is a scalar, null, or nested sequence instead of a mapping.
Source
Thrown at src/Humanizer.SourceGenerators/Generators/ProfileCatalogs/InflectionCatalogParsing.cs:247
{
throw new InvalidOperationException("Active inflection bundle must define lexemes.");
}
if (lexemeSequence.Items.IsEmpty)
{
return allowEmpty
? []
: throw new InvalidOperationException(
"Active inflection bundle must define lexemes.");
}
var ids = new HashSet<string>(StringComparer.Ordinal);
var lexemes = ImmutableArray.CreateBuilder<InflectionLexemeInput>();
foreach (var value in lexemeSequence.Items)
{
if (value is not SimpleYamlMapping lexeme)
{
throw new InvalidOperationException("Inflection lexemes must be mappings.");
}
ValidateProperties(
lexeme,
"Inflection lexeme",
"id", "pos", "countability", "sense", "forms", "sources");
var id = GetRequiredScalar(lexeme, "id", "Inflection lexeme must define id");
if (!ids.Add(id))
{
throw new InvalidOperationException($"Duplicate inflection lexeme id '{id}'.");
}
if (GetRequiredScalar(lexeme, "pos", $"Inflection lexeme '{id}' must define pos") != "noun")
{
throw new InvalidOperationException($"Inflection lexeme '{id}' pos must be 'noun'.");
}
var countability = GetRequiredScalar(View on GitHub (pinned to ffc2b77c0f)
Solutions
- Make each list item a mapping containing id, pos, countability, forms, and sources
Example fix
# before
lexemes:
- 'zz.noun.cat'
- 'zz.noun.dog'
# after
lexemes:
- id: 'zz.noun.cat'
pos: 'noun'
countability: 'count'
forms: { ... }
sources: [ 'fixture' ] Defensive patterns
Strategy: validation
Validate before calling
foreach (var item in lexemeSequence.Items)
if (item is not SimpleYamlMapping)
Report($"{locale}: each lexemes entry must be a mapping."); Type guard
static bool AllLexemesAreMappings(SimpleYamlSequence s) =>
s.Items.All(i => i is SimpleYamlMapping); Prevention
- Validate YAML structure with an editor schema; each '- ' item must hold key: value pairs
When it happens
Trigger: An item under 'lexemes:' is a bare string/number or a nested sequence rather than a mapping.
Common situations: A YAML indentation slip flattening '- id: ...' into a flat list of scalars; pasting a list of ids instead of full lexeme objects.
Related errors
- Inflection defines unsupported quantity selector; expected '
- Inflection quantitySelector 'exact-numeric-singleton' requir
- Inflection quantitySelector 'exact-numeric-singleton' cannot
- Inflection display category 'one' is unreachable without qua
- Active inflection bundle must define lexemes.
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/bba0101084da0e4b.
Report an issue: GitHub.