Humanizr/Humanizer · error · InvalidOperationException

'{path}.unsupported' must be true.

Error message

'{path}.unsupported' must be true.

What it means

Mirror of error 102 for the 'unsupported' flag. ParseUnit (DurationCaseModels.cs:1170-1173) accepts 'unsupported' only when it is exactly boolean true. A unit is either explicitly unsupported (true) or it carries a phrase/sameAsNominative; false or non-boolean values are invalid.

Source

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

            var mapping = ExpectMapping(value, path);
            if (mapping.GetScalar("sameAsNominative") is { } sameAsNominative)
            {
                RejectUnknownKeys(mapping, path, ["sameAsNominative"]);
                if (!bool.TryParse(sameAsNominative, out var enabled) || !enabled)
                {
                    throw new InvalidOperationException($"'{path}.sameAsNominative' must be true.");
                }

                return new DurationCaseUnit(DurationCaseUnitKind.SameAsNominative, null);
            }

            if (mapping.GetScalar("unsupported") is { } unsupported)
            {
                RejectUnknownKeys(mapping, path, ["unsupported"]);
                if (!bool.TryParse(unsupported, out var enabled) || !enabled)
                {
                    throw new InvalidOperationException($"'{path}.unsupported' must be true.");
                }

                return new DurationCaseUnit(DurationCaseUnitKind.Unsupported, null);
            }

            var phrase = LocalePhraseNormalization.ParseTimeSpanPhrase(value, path);
            if (phrase.Single is null ||
                phrase.Multiple?.Forms is null)
            {
                throw new InvalidOperationException(
                    $"Case overlay '{path}' must explicitly define singular and numeric multiple forms.");
            }

            return new DurationCaseUnit(DurationCaseUnitKind.Phrase, phrase);
        }

        static bool ContainsInheritanceMarker(SimpleYamlValue value) =>
            value switch

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. If the unit is genuinely unsupported, set 'unsupported: true' (plain YAML boolean).
  2. Otherwise remove the unsupported key and provide sameAsNominative: true or a full phrase: block.

Example fix

# before
year:
  unsupported: false
# after - unit is supported
year:
  sameAsNominative: true
Defensive patterns

Strategy: validation

Validate before calling

# An unsupported unit must be exactly true
foreach ($u in $caseUnits.GetEnumerator()) {
    if ($u.Value -is [hashtable] -and $u.Value.ContainsKey('unsupported') `
        -and $u.Value.unsupported -ne $true) {
        throw "unit '$($u.Key)': unsupported must be true (got $($u.Value.unsupported))"
    }
}

Prevention

When it happens

Trigger: unsupported is set to false, a quoted string, or another non-true scalar.

Common situations: A contributor marks a unit unsupported then sets 'unsupported: false' to toggle it back — the schema has no false branch, so the key should be removed instead.

Related errors


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