Humanizr/Humanizer · critical · InvalidOperationException

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

Error message

Locale '{localeCode}.surfaces.calendar.monthsGenitive' must be a sequence of exactly 12 strings.

What it means

Thrown by AddCalendarFeatures when surfaces.calendar.monthsGenitive is present and months is present, but the genitive list is not a YAML sequence of exactly 12 entries. Genitive months must mirror the nominative list one-to-one across all twelve months.

Source

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

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

            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.");
                }

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Provide exactly 12 genitive month strings in surfaces.calendar.monthsGenitive.
  2. If a month has no distinct genitive form, repeat its nominative name for that slot rather than omitting it.
  3. Rebuild to confirm the length guard passes.

Example fix

# before
calendar:
  months: [a, b, c, d, e, f, g, h, i, j, k, l]
  monthsGenitive: [genA, genB]
# after
calendar:
  months: [a, b, c, d, e, f, g, h, i, j, k, l]
  monthsGenitive: [genA, genB, genC, genD, genE, genF, genG, genH, genI, genJ, genK, genL]
Defensive patterns

Strategy: validation

Validate before calling

# Ensure surfaces.calendar.monthsGenitive is a 12-element sequence.
# Parse the YAML and assert: $gen -is [array] -and $gen.Count -eq 12.

Prevention

When it happens

Trigger: A locale YAML defines monthsGenitive with fewer/more than 12 entries, as a mapping, or as a scalar. The guard at CanonicalLocaleAuthoring.cs:481-485 requires a SimpleYamlSequence of length 12.

Common situations: Translating only some genitive forms and deferring the rest; a locale that has genitive forms for only some months (the schema still requires all 12); copy-paste miscount.

Related errors


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