Humanizr/Humanizer · error · InvalidOperationException
Inflection source '{entry.Key}' must define non-empty kind a
Error message
Inflection source '{entry.Key}' must define non-empty kind and locator. What it means
Each entry in the inflection catalog's 'sources:' mapping must be a YAML map with non-empty 'kind' and 'locator' scalar fields. The 'kind' identifies the source type (e.g., 'cldr', 'treebank') and 'locator' identifies where the data comes from. This validator rejects source definitions missing either field or containing empty values.
Source
Thrown at src/Humanizer.SourceGenerators/Generators/ProfileCatalogs/InflectionCatalogValidation.cs:116
{
foreach (var source in GetRequiredStrings(mapping, "sources", $"{subject} must define sources"))
{
if (!sourceIds.Contains(source))
{
throw new InvalidOperationException($"{subject} references unknown source '{source}'.");
}
}
}
static void ValidateSourceDefinitions(SimpleYamlMapping sources)
{
foreach (var entry in sources.Values)
{
if (entry.Value is not SimpleYamlMapping source ||
source.GetScalar("kind") is not { Length: > 0 } ||
source.GetScalar("locator") is not { Length: > 0 })
{
throw new InvalidOperationException(
$"Inflection source '{entry.Key}' must define non-empty kind and locator.");
}
ValidateProperties(
source,
$"Inflection source '{entry.Key}'",
"kind", "locator", "revision", "credit");
foreach (var optionalProperty in new[] { "revision", "credit" })
{
if (source.TryGetValue(optionalProperty, out var optionalValue) &&
(optionalValue is not SimpleYamlScalar optionalScalar ||
string.IsNullOrWhiteSpace(optionalScalar.Value)))
{
throw new InvalidOperationException(
$"Inflection source '{entry.Key}' {optionalProperty} must be a non-empty scalar.");
}
}
}View on GitHub (pinned to ffc2b77c0f)
Solutions
- Add both 'kind' and 'locator' as non-empty string scalars to the offending source entry.
- If the source entry is a scalar or wrong shape, convert it to a YAML mapping with 'kind' and 'locator' keys.
- Remove the incomplete source definition if it was added by mistake, and remove all references to it.
Example fix
# before
sources:
custom1:
kind: 'dictionary'
# after
sources:
custom1:
kind: 'dictionary'
locator: 'Oxford English Dictionary, 2024 ed.' Defensive patterns
Strategy: validation
Validate before calling
# Before building, verify each source has non-empty kind and locator.
python3 -c "
import yaml, sys
for f in sys.argv[1:]:
d = yaml.safe_load(open(f))
sources = (d.get('inflection',{}).get('sources') or {})
for sid, sdef in sources.items():
if not isinstance(sdef, dict):
print(f'{f}: source {sid!r} is not a mapping')
continue
if not (sdef.get('kind') or '').strip():
print(f'{f}: source {sid!r} missing kind')
if not (sdef.get('locator') or '').strip():
print(f'{f}: source {sid!r} missing locator')
" src/Humanizer/Locales/*.yml Prevention
- Use a YAML schema or template that includes kind and locator as required keys for every source entry.
- During code review, verify new source definitions have both fields filled with non-empty strings.
- Add a JSON Schema validation step in CI for locale YAML files.
When it happens
Trigger: A source entry in the YAML is not a SimpleYamlMapping, or its 'kind' or 'locator' scalar is missing/empty. For example, a source defined as just a string instead of a map, or a map with only 'kind' and no 'locator'.
Common situations: Creating a new source entry and forgetting the 'locator' field. Defining a source as a bare string instead of a key-value map. Leaving a placeholder empty value during incremental editing.
Related errors
- {subject} references unknown source '{source}'.
- Inflection source '{entry.Key}' {optionalProperty} must be a
- '{path}' must define provenance.
- '{path}.provenance' must be a sequence.
- '{path}.provenance' must contain non-empty source identifier
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/b873cde4628e3bc3.
Report an issue: GitHub.