class Exceptions {

    static void report(CommandSender sender, CommandSyntaxException exception) {
        var listener = from(sender);
        
        listener.sendFailureMessage(ChatComponentUtils.a(exception.getRawMessage()));
        
        var input = exception.getInput();
        if (input != null && exception.getCursor() >= 0) {
            var index = Math.min(input.length(), exception.getCursor());

            var text = (new ChatComponentText("")).a(EnumChatFormat.GRAY).format(modifier -> 
                modifier.setChatClickable(new ChatClickable(ChatClickable.EnumClickAction.SUGGEST_COMMAND, input))
            );
            
            if (index > 10) {
                text.c("...");
            }

            text.c(input.substring(Math.max(0, index - 10), index));
            
            if (index < input.length()) {
                var error = new ChatComponentText(input.substring(index)).a(new EnumChatFormat[]{EnumChatFormat.RED, EnumChatFormat.UNDERLINE});
                text.addSibling(error);
            }
            
            var context = new ChatMessage("command.context.here").a(new EnumChatFormat[]{EnumChatFormat.RED, EnumChatFormat.ITALIC});
            text.addSibling(context);
            
            listener.sendFailureMessage(text);
        }
    }

}