Humanizr/Humanizer · error · InvalidOperationException

'{path}.provenance' references unknown source '{sourceId}'.

Error message

'{path}.provenance' references unknown source '{sourceId}'.

What it means

Thrown by ValidateProvenance when a source ID in the provenance sequence does not match any key in the locale's sources dictionary. Every provenance entry must reference a source defined in the durationCases.sources section.

Source

Thrown at src/Humanizer.SourceGenerators/Common/DurationCaseModels.cs:1086

                result.Add(scalar.Value);
            }

            if (required && result.Count == 0)
            {
                throw new InvalidOperationException($"'{path}.provenance' must not be empty.");
            }

            return result.MoveToImmutable();
        }

        static void ValidateProvenance(
            ImmutableArray<string> provenance,
            ImmutableDictionary<string, DurationCaseSource> sources,
            string path)
        {
            foreach (var sourceId in provenance.Where(sourceId => !sources.ContainsKey(sourceId)))
            {
                throw new InvalidOperationException(
                    $"'{path}.provenance' references unknown source '{sourceId}'.");
            }
        }

        static string RequireScalar(SimpleYamlMapping mapping, string key, string path) =>
            mapping.GetScalar(key)
            ?? throw new InvalidOperationException($"'{path}' must define scalar '{key}'.");

        static string RequireReason(string reason, string path) =>
            string.IsNullOrWhiteSpace(reason)
                ? throw new InvalidOperationException($"'{path}' must not be empty.")
                : reason;

        static ImmutableDictionary<string, DurationCaseRealization> EmptyRealizations() =>
            ImmutableDictionary<string, DurationCaseRealization>.Empty.WithComparers(StringComparer.Ordinal);

        static DurationCaseOverlay CreateBaseDurationOverlay()
        {

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Check the source ID named in the error message against the locale's 'sources' section.
  2. Either add a source entry with that ID (including kind, url, revision, locator, and credit fields) or correct the provenance reference to match an existing source ID.
  3. Rebuild to confirm all provenance references resolve.

Example fix

# before — provenance references 'cldr-43' but sources only defines 'cldr-42'
sources:
  cldr-42:
    kind: cldr
    url: ...
    ...
second:
  phrase: ...
  provenance: [cldr-43]
# after
second:
  phrase: ...
  provenance: [cldr-42]
Defensive patterns

Strategy: validation

Validate before calling

# Verify every provenance source ID exists in the sources registry
# python: source_ids = set(yaml['durationCases']['sources'].keys())
#         for unit in all_units:
#             for sid in unit.get('provenance', []):
#                 assert sid in source_ids, f'unknown source {sid}'

Prevention

When it happens

Trigger: A unit realization's provenance lists a source ID (e.g. 'cldr-42') but no matching entry exists in the locale's sources registry.

Common situations: A contributor adds a new source ID to a provenance list but forgets to declare the corresponding source object in the 'sources' section. Also occurs when a source ID is renamed in the sources section but not updated in provenance references, or vice versa.

Related errors


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