Repository: microsoft/garnet
File: libs/server/Resp/AdminCommands.cs (C#)

Code before:
                return AbortWithErrorMessage(CmdStrings.RESP_ERR_GENERIC_CLUSTER_DISABLED);
            }

            clusterSession.ProcessClusterCommands(command, ref parseState, ref dcurr, ref dend);
            return true;
        }

        private bool NetworkDebug()
        {
            if (parseState.Count == 0)
            {
                return AbortWithWrongNumberOfArguments(nameof(RespCommand.DEBUG));
            }

            if (
                    (storeWrapper.serverOptions.EnableDebugCommand == ConnectionProtectionOption.No)
                 || (
                        (storeWrapper.serverOptions.EnableDebugCommand == ConnectionProtectionOption.Local)
                      && !networkSender.IsLocalConnection()
                    )
               )
            {
                return AbortWithErrorMessage(CmdStrings.GenericErrCommandDisallowedWithOption, RespCommand.DEBUG, "enable-debug-command");
            }

            var command = parseState.GetArgSliceByRef(0).ReadOnlySpan;

            if (command.EqualsUpperCaseSpanIgnoringCase(CmdStrings.PANIC))
                // Throwing an exception is intentional and desirable for this command.
                throw new GarnetException(LogLevel.Debug, panic: true);

            if (command.EqualsUpperCaseSpanIgnoringCase(CmdStrings.ERROR))
            {
                if (parseState.Count != 2)
                {
                    return AbortWithWrongNumberOfArguments("error");
                }

                WriteError(parseState.GetString(1));
                return true;
            }

            if (command.EqualsUpperCaseSpanIgnoringCase(CmdStrings.LOG))
            {
                if (parseState.Count != 2)
                {
                    return AbortWithWrongNumberOfArguments("log");
                }

                logger?.LogInformation("DEBUG LOG: {LOG}", parseState.GetString(1));


Review comment (bug):
Error should be `ERR unknown subcommand or wrong number of arguments for 'error'. Try DEBUG HELP.` (we should add a template for this probably)

Code after:

            if (!CanRunDebug())
            {
                return AbortWithErrorMessage(CmdStrings.GenericErrCommandDisallowedWithOption, RespCommand.DEBUG, "enable-debug-command");
            }

            var command = parseState.GetArgSliceByRef(0).ReadOnlySpan;

            if (command.EqualsUpperCaseSpanIgnoringCase(CmdStrings.PANIC))
                // Throwing an exception is intentional and desirable for this command.
                throw new GarnetException(LogLevel.Debug, panic: true);

            if (command.EqualsUpperCaseSpanIgnoringCase(CmdStrings.ERROR))
            {
                if (parseState.Count != 2)
                {
                    return AbortWithWrongNumberOfArgumentsOrUnknownSubcommand(Encoding.ASCII.GetString(command),
                                                                              nameof(RespCommand.DEBUG));
                }

                WriteError(parseState.GetString(1));
                return true;
            }

            if (command.EqualsUpperCaseSpanIgnoringCase(CmdStrings.LOG))
            {
                if (parseState.Count != 2)
                {
                    return AbortWithWrongNumberOfArgumentsOrUnknownSubcommand(Encoding.ASCII.GetString(command),
                                                                              nameof(RespCommand.DEBUG));
                }

                logger?.LogInformation("DEBUG LOG: {LOG}", parseState.GetString(1));

                WriteDirect(CmdStrings.RESP_OK);
                return true;
            }

            if (command.EqualsUpperCaseSpanIgnoringCase(CmdStrings.HELP))
            {
                var help = new string[]
                {
                    "DEBUG <subcommand> [<arg> [value] [opt] ...]. Subcommands are:",
                    "ERROR <string>",
                    "\tReturn a Redis protocol error with <string> as message. Useful for clients",
                    "\tunit tests to simulate Redis errors.",
                    "LOG <message>",
                    "\tWrite <message> to the server log.",
                    "PANIC",
                    "\tCrash the server simulating a panic.",
                    "HELP",