Humanizr/Humanizer · error · InvalidOperationException

'{path}.provenance' contains duplicate source '{scalar.Value

Error message

'{path}.provenance' contains duplicate source '{scalar.Value}'.

What it means

Thrown by ParseProvenance when the same source identifier string appears more than once in the provenance sequence. The parser uses a HashSet to track seen IDs and throws on any duplicate to prevent redundant or erroneous citations.

Source

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

            if (value is not SimpleYamlSequence sequence)
            {
                throw new InvalidOperationException($"'{path}.provenance' must be a sequence.");
            }

            var result = ImmutableArray.CreateBuilder<string>(sequence.Items.Length);
            var seen = new HashSet<string>(StringComparer.Ordinal);
            foreach (var item in sequence.Items)
            {
                if (item is not SimpleYamlScalar scalar || string.IsNullOrWhiteSpace(scalar.Value))
                {
                    throw new InvalidOperationException(
                        $"'{path}.provenance' must contain non-empty source identifiers.");
                }

                if (!seen.Add(scalar.Value))
                {
                    throw new InvalidOperationException(
                        $"'{path}.provenance' contains duplicate source '{scalar.Value}'.");
                }

                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)

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Inspect the provenance list at the reported path and find the duplicated source ID named in the message.
  2. Remove the duplicate so each source ID appears exactly once.
  3. Rebuild to confirm no duplicates remain.

Example fix

# before
provenance: [cldr-42, grammar-ref, cldr-42]
# after
provenance: [cldr-42, grammar-ref]
Defensive patterns

Strategy: validation

Validate before calling

# Verify no duplicate source IDs in provenance
# python: assert len(unit['provenance']) == len(set(unit['provenance'])), 'duplicate provenance'

Prevention

When it happens

Trigger: The provenance list contains the same source ID twice, e.g. [cldr-42, cldr-42].

Common situations: A contributor merges two provenance lists or copies entries and accidentally leaves a duplicate source ID. Also occurs when a source is cited under slightly different keys that resolve to the same string.

Related errors


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