Humanizr/Humanizer · error · InvalidOperationException

Unsupported YAML node.

Error message

Unsupported YAML node.

What it means

Thrown by AppendYamlValue during YAML serialization when the value node is not a SimpleYamlMapping, SimpleYamlSequence, or SimpleYamlScalar. This is an internal defensive assertion — the simple YAML model only has three node types, so reaching the default branch indicates either a corrupt node or a new node type was introduced without updating the serializer.

Source

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

        static void AppendYamlValue(StringBuilder builder, SimpleYamlValue value, int indent)
        {
            switch (value)
            {
                case SimpleYamlMapping mapping:
                    AppendYamlMapping(builder, mapping, indent);
                    break;

                case SimpleYamlSequence sequence:
                    AppendYamlSequence(builder, sequence, indent);
                    break;

                case SimpleYamlScalar scalar:
                    builder.Append(' ', indent);
                    builder.AppendLine(QuoteScalar(scalar));
                    break;

                default:
                    throw new InvalidOperationException("Unsupported YAML node.");
            }
        }

        static void AppendYamlMapping(StringBuilder builder, SimpleYamlMapping mapping, int indent)
        {
            foreach (var entry in mapping.Values)
            {
                if (entry.Value is SimpleYamlScalar scalar)
                {
                    AppendIndentedScalar(builder, indent, entry.Key, scalar);
                    continue;
                }

                builder.Append(' ', indent);
                builder.Append(entry.Key);
                builder.AppendLine(":");
                AppendYamlValue(builder, entry.Value, indent + 2);
            }

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Report this as a bug — the YAML serializer should handle all SimpleYamlValue subtypes. Check whether SimpleYamlParser was modified to emit a new node type.
  2. Inspect the locale YAML that triggered the serialization to see if it has an unusual structure that confused the parser.
  3. Add the missing node-type case to AppendYamlValue if a legitimate new SimpleYamlValue subtype was introduced.
Defensive patterns

Strategy: try-catch

Type guard

static bool IsKnownYamlNode(SimpleYamlValue value) =>
    value is SimpleYamlMapping or SimpleYamlSequence or SimpleYamlScalar;

Try / catch

// This is an internal assertion — catch only to produce diagnostics, not to recover
try
{
    LegacyLocaleMigration.ConvertToCanonicalYaml(localeCode, fileText);
}
catch (InvalidOperationException ex) when (ex.Message == "Unsupported YAML node.")
{
    // This indicates a bug in the YAML parser or model, not an authoring error.
    // Report it upstream rather than trying to work around it.
    throw new InvalidOperationException($"Internal YAML serialization error for locale '{localeCode}'. Report as a bug.", ex);
}

Prevention

When it happens

Trigger: LegacyLocaleMigration's AppendYamlValue is called while building canonical YAML from a legacy mapping. The default case fires if SimpleYamlParser produced a null or a subtype not covered by the three cases. This should never happen with well-formed input from the parser.

Common situations: This is effectively a bug indicator, not an authoring error. It may surface if a custom or patched SimpleYamlValue subclass is introduced, or if the YAML parser has a defect producing unexpected node types. Contributors should not normally see this.

Related errors


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