spectreconsole/spectre.console · error · InvalidOperationException

Emoji has null label

Error message

Emoji has null label

What it means

Thrown by EmojiModel.ParseAll while reading emoji.json: an array element had no usable label string (GetProperty("label").GetString() returned null). Each emoji must have a label, so this is treated as malformed data and parsing stops.

Source

Thrown at src/Spectre.Console.SourceGenerator/Emojis/EmojiModel.cs:38

/// <summary>
/// Parses emoji data from JSON.
/// </summary>
internal static class EmojiParser
{
    /// <summary>
    /// Parses the emoji.json file and returns all emoji models.
    /// Filters out emojis with multiple codepoints (combinators).
    /// </summary>
    public static EquatableArray<EmojiModel> ParseAll(string json)
    {
        var document = JsonDocument.Parse(json);
        var emojis = new List<EmojiModel>();

        foreach (var element in document.RootElement.EnumerateArray())
        {
            var label = element.GetProperty("label").GetString()
                ?? throw new InvalidOperationException("Emoji has null label");
            var hexcode = element.GetProperty("hexcode").GetString()
                ?? throw new InvalidOperationException("Emoji has null hexcode");
            var emoji = element.GetProperty("emoji").GetString()
                ?? throw new InvalidOperationException("Emoji has null emoji");

            // Skip anything that is not a single code point for now
            if (hexcode.Contains("-"))
            {
                continue;
            }

            // Transform hexcode to Unicode escape sequence
            var code = TransformToUnicode(hexcode);

            // If the emoji does not have the Emoji_Presentation=Yes property,
            // then it doesn't have a Variation Selector-16 suffix, and we should add it.
            var codepoint = int.Parse(hexcode, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
            if (!HasEmojiPresentation(codepoint))

View on GitHub (pinned to 0acc92fada)

Solutions

  1. Find the offending element (it will be the next one parsed) and give it a non-null label
  2. Restore emoji.json from the Spectre.Console package
  3. Validate the JSON structure before replacing the bundled file

Example fix

// before
{ "label": null, "hexcode": "1F600", "emoji": "\ud83d\ude00" }
// after
{ "label": "grinning face", "hexcode": "1F600", "emoji": "\ud83d\ude00" }
Defensive patterns

Strategy: validation

Validate before calling

// Scan emoji.json for null labels before replacing the file
using var doc = JsonDocument.Parse(File.ReadAllText("emoji.json"));
foreach (var e in doc.RootElement.EnumerateArray())
    if (e.GetProperty("label").ValueKind == JsonValueKind.Null)
        Console.Error.WriteLine("emoji has null label");

Prevention

When it happens

Trigger: An emoji.json element contains "label": null or otherwise yields a null string for the label property.

Common situations: Hand-editing or forking emoji.json with a null label; truncated download of the emoji data; schema drift.

Related errors


AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13). Data as JSON: /api/errors/5076df9b74f2545c. Report an issue: GitHub.