spectreconsole/spectre.console · error · InvalidOperationException
Emoji has null emoji
Error message
Emoji has null emoji
What it means
Thrown by EmojiModel.ParseAll: an emoji.json element had label and hexcode but its emoji property parsed to null. The literal emoji character is required for the generated code, so a null value aborts parsing.
Source
Thrown at src/Spectre.Console.SourceGenerator/Emojis/EmojiModel.cs:42
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))
{
code += "\\uFE0F";
}
View on GitHub (pinned to 0acc92fada)
Solutions
- Locate the offending element and restore the literal emoji string
- Restore emoji.json from the Spectre.Console package (keep UTF-8 encoding intact)
- Validate the JSON before replacing the bundled file
Example fix
// before
{ "label": "grinning face", "hexcode": "1F600", "emoji": null }
// after
{ "label": "grinning face", "hexcode": "1F600", "emoji": "\ud83d\ude00" } Defensive patterns
Strategy: validation
Validate before calling
// Scan emoji.json for null emoji literals before replacing the file
using var doc = JsonDocument.Parse(File.ReadAllText("emoji.json"));
foreach (var e in doc.RootElement.EnumerateArray())
if (e.GetProperty("emoji").ValueKind == JsonValueKind.Null)
Console.Error.WriteLine("emoji has null emoji literal"); Prevention
- Validate edited emoji.json before shipping
- Preserve UTF-8 encoding when copying the file
When it happens
Trigger: An emoji.json element contains "emoji": null or otherwise yields null for the emoji property.
Common situations: Editing emoji.json and clearing the literal glyph; encoding loss stripping the emoji field to null; schema drift.
Related errors
- Emoji has null label
- Emoji has null hexcode
- Color {number} has null name
- Color {number} has null alias
- Failed to read emoji.json at {file.Path}
AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13).
Data as JSON: /api/errors/dd60a7f81ac00ce7.
Report an issue: GitHub.