Humanizr/Humanizer · critical · InvalidOperationException

Locale '{localeCode}.surfaces.calendar.monthsGenitive' items

Error message

Locale '{localeCode}.surfaces.calendar.monthsGenitive' items must be scalar strings.

What it means

Thrown by AddCalendarFeatures when surfaces.calendar.monthsGenitive is a 12-element sequence but one or more items is not a YAML scalar string (e.g. a nested mapping or sequence). Genitive month names must be plain strings to be emitted into the generated calendar table.

Source

Thrown at src/Humanizer.SourceGenerators/Common/CanonicalLocaleAuthoring.cs:489

            }

            if (calendarSurface.TryGetValue("monthsGenitive", out var monthsGenitiveValue))
            {
                if (!hasMonths)
                {
                    throw new InvalidOperationException(
                        $"Locale '{localeCode}.surfaces.calendar.monthsGenitive' requires 'months' to also be present.");
                }

                if (monthsGenitiveValue is not SimpleYamlSequence genitiveSeq || genitiveSeq.Items.Length != 12)
                {
                    throw new InvalidOperationException(
                        $"Locale '{localeCode}.surfaces.calendar.monthsGenitive' must be a sequence of exactly 12 strings.");
                }

                if (genitiveSeq.Items.Any(static item => item is not SimpleYamlScalar))
                {
                    throw new InvalidOperationException(
                        $"Locale '{localeCode}.surfaces.calendar.monthsGenitive' items must be scalar strings.");
                }
            }

            if (calendarSurface.TryGetValue("hijriMonths", out var hijriMonthsValue))
            {
                if (hijriMonthsValue is not SimpleYamlSequence hijriSeq || hijriSeq.Items.Length != 12)
                {
                    throw new InvalidOperationException(
                        $"Locale '{localeCode}.surfaces.calendar.hijriMonths' must be a sequence of exactly 12 strings.");
                }

                foreach (var item in hijriSeq.Items)
                {
                    if (item is not SimpleYamlScalar scalar)
                    {
                        throw new InvalidOperationException(
                            $"Locale '{localeCode}.surfaces.calendar.hijriMonths' items must be scalar strings.");

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Flatten every genitive month entry to a plain scalar string.
  2. Confirm each item is inline like '- Stycznia' or an inline '[...]' list, not a nested block.
  3. Rebuild to confirm the scalar-items check passes.

Example fix

# before
calendar:
  monthsGenitive:
    - name: Stycznia
# after
calendar:
  monthsGenitive: [Stycznia, Lutego, Marca, Kwietnia, Maja, Czerwca, Lipca, Sierpnia, Września, Października, Listopada, Grudnia]
Defensive patterns

Strategy: validation

Validate before calling

# Ensure every monthsGenitive item is a scalar string.
# After parsing: $gen | ForEach-Object { $_ -is [string] }.

Prevention

When it happens

Trigger: A genitive month entry is a nested object or sub-list. The check genitiveSeq.Items.Any(item => item is not SimpleYamlScalar) at CanonicalLocaleAuthoring.cs:487-491 fires.

Common situations: Pasting CLDR objects that wrap month names in metadata; mis-indenting list items into mappings; converting from a structured source.

Related errors


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