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

  1. Open the locale YAML and inspect the calendar.{key} sequence flagged in the error message.
  2. Ensure every item in that sequence is a plain or quoted string scalar with no colons or nested mappings.
  3. Quote month names that contain special YAML characters (colons, brackets) using single or double quotes.
  4. 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

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


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