Humanizr/Humanizer · error · InvalidOperationException
calendar.{key} items must be strings.
Error message
calendar.{key} items must be strings. What it means
Thrown during source generation by ExtractCalendarMonths when parsing a calendar sequence (calendar.months, calendar.monthsGenitive, or calendar.hijriMonths) from an ordinal-date locale YAML. Each item in the YAML sequence must be a scalar string; if any item is a mapping, null, or another non-scalar YAML node, the generator rejects it with this message naming the offending key.
Source
Thrown at src/Humanizer.SourceGenerators/Generators/ProfileCatalogs/OrdinalDateProfileCatalogInput.cs:48
AddProfile(dateOnlyProfiles, locale.DateOnlyToOrdinalWords, seenDateOnly, months, monthsGenitive, hijriMonths);
}
return new OrdinalDateProfileCatalogInput(dateProfiles.ToImmutable(), dateOnlyProfiles.ToImmutable());
}
static ImmutableArray<string> ExtractCalendarMonths(SimpleYamlMapping? calendar, string key)
{
if (calendar is null || !calendar.TryGetValue(key, out var value) || value is not SimpleYamlSequence sequence)
{
return ImmutableArray<string>.Empty;
}
var builder = ImmutableArray.CreateBuilder<string>(sequence.Items.Length);
foreach (var item in sequence.Items)
{
if (item is not SimpleYamlScalar scalar)
{
throw new InvalidOperationException($"calendar.{key} items must be strings.");
}
builder.Add(scalar.Value);
}
return builder.MoveToImmutable();
}
static void AddProfile(
ImmutableArray<OrdinalDateProfileDefinition>.Builder profiles,
LocaleFeature? feature,
HashSet<string> seenProfiles,
ImmutableArray<string> months,
ImmutableArray<string> monthsGenitive,
ImmutableArray<string> hijriMonths)
{
if (feature is not { UsesGeneratedProfile: true } ||
!seenProfiles.Add(feature.ProfileName!))View on GitHub (pinned to ffc2b77c0f)
Solutions
- Open the locale YAML and inspect the calendar.{key} sequence flagged in the error message.
- Ensure every item in that sequence is a plain or quoted string scalar with no colons or nested mappings.
- Quote month names that contain special YAML characters (colons, brackets) using single or double quotes.
- Rebuild to confirm the generator parses all month entries as strings.
Example fix
# locale YAML — before (colon in month name parsed as mapping)
calendar:
months:
- January
- month: February
# after
calendar:
months:
- January
- February Defensive patterns
Strategy: validation
Validate before calling
// Before building, validate that all calendar.{key} sequences in ordinal-date
// locale YAML contain only string scalars. Use a YAML parser to load and check:
// foreach item in sequence: assert item is scalar. Prevention
- Quote any month name containing YAML special characters (colons, brackets, commas).
- Validate YAML indentation in locale files — tabs are not allowed in YAML.
- Run a YAML syntax check on modified locale files before building.
When it happens
Trigger: An ordinal-date locale YAML declares a calendar.months (or monthsGenitive or hijriMonths) sequence, but one or more entries are not plain string scalars — for example, a nested mapping with a value key, a quoted multi-word structure parsed as a map, or a null entry.
Common situations: A maintainer edits month names in a locale YAML and accidentally introduces a syntax error (e.g. a colon inside a month name that YAML interprets as a key-value pair, or a tab indentation issue that produces a nested node).
Related errors
- Ordinal date profile '{profile.ProfileName}' uses MMM (abbre
- Ordinal date profile '{profile.ProfileName}' has calendar mo
- Ordinal date profile '{profile.ProfileName}' has calendar mo
- Unsupported ordinal date engine '{profile.Engine}'.
- Billion-word cardinal strategy requires a singular billion w
AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13).
Data as JSON: /api/errors/27eeba38994d9102.
Report an issue: GitHub.