mojira.dev
MC-59511

Tellraw has incomplete error message when key determining text to display is missing

The bug

When no key determining the text to display is present, the game shows an error message, however this error message is incomplete.

How to reproduce

Perform this command:

/tellraw @p {}

The error message is:

Invalid json:

The correct error message would be:

Invalid json: Don't know how to turn {} into a Component

The reason

The following is based on decompiled version of Minecraft 1.8 using MCP. All method and class names are the names used in the decompiled version.

The reason for this bug is that the public void processCommand(ICommandSender sender, String[] args) throws CommandException method of the net.minecraft.command.server.CommandMessageRaw (command /tellraw) and the net.minecraft.command.CommandTitle (command /title) class display any exception that occurs when the Json string is parsed using Throwable org.apache.commons.lang3.exception.ExceptionUtils.getRootCause(Throwable throwable). As there are however exceptions that are not thrown by the Json parser but by the net.minecraft.util.IChatComponent.Serializer class itself. The root cause is null. Instead it should just print the message of the exception.
The following shows how this could by done for the net.minecraft.command.server.CommandMessageRaw class.

public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 2)
    {
        throw new WrongUsageException("commands.tellraw.usage", new Object[0]);
    }
    else
    {
        EntityPlayerMP var3 = getPlayer(sender, args[0]);
        String var4 = func_180529_a(args, 1);

        try
        {
            IChatComponent var5 = IChatComponent.Serializer.jsonToComponent(var4);
            var3.addChatMessage(ChatComponentProcessor.func_179985_a(sender, var5, var3));
        }
        catch (JsonParseException var7)
        {
            // Changed this
            //Throwable var6 = ExceptionUtils.getRootCause(var7);
            //throw new SyntaxErrorException("commands.tellraw.jsonException", new Object[] {var6 == null ? "" : var6.getMessage()});
            throw new SyntaxErrorException("commands.tellraw.jsonException", new Object[] {var7.getMessage()});
        }
    }
}

Linked issues

Comments 5

Fixed in some 1.9 snapshot.
Output now is

[23:26:44] Invalid json: malformed JSON at line 1 column 3

That is because the key was missing quotes around it, I changed the description now, please reopen this report

Don't see a bug here. The JSON text

{}

is simply an empty container of zero bytes, so the JSON parser spits out

Invalid json:<ZERO_BYTE_LONG_STRING>

I updated the description

This is fixed in 17w45b and possibly earlier versions

marcono1234

michael

Confirmed

/tellraw, JSON, command-block-output, command_block, previous-output, tag

Minecraft 14w26c, Minecraft 14w28a, Minecraft 14w29b, Minecraft 14w30c, Minecraft 14w31a, ..., Minecraft 17w16b, Minecraft 17w17b, Minecraft 17w18b, Minecraft 1.12 Pre-Release 2, Minecraft 1.12.2

Minecraft 15w45a, Minecraft 17w45a

Retrieved