mojira.dev
MC-279191

Running '/debug function' from inside a function run with the '/function' command causes an error

Using /function to run a function containing a debug function command causes an error.
It is worth noting that using /debug function to run the function instead correctly causes the command to fail with the message "Can't trace from inside of function" instead of throwing an error.

How to reproduce:

The /debug command requires a permission level of 3, and since functions normally run on a permission level of 2, we need to use a dedicated server, since it allows for changing the permission level functions run on. The attached data pack contains a function with a simple say command, and another that runs debug function on the first function:

[media]
  1. On a dedicated server setup, open the server.properties file, change the value of the property function-permission-level to 3 and save the file.

  2. Install the attached data pack.

  3. Start the server and join it.

  4. Make sure that you are an operator with a permission level of at least 3.

  5. Execute the following command:

    /function mc-279191:debug_function

Expected result:

Running /debug function from inside a function run with the /function command would cause it to fail with the message "Can't trace from inside of function."

Observed result:

Running /debug function from inside a function run with the /function command causes it to throw an error and print the message "An unexpected error occurred trying to execute that command" to the chat, with the following hover event:

Cannot invoke "net.minecraft.server.MinecraftServer.getFunctions()" because the return value of "net.minecraft.commands.CommandSourceStack.getServer()" is null

Stack trace:

java.lang.NullPointerException: Cannot invoke "net.minecraft.server.MinecraftServer.getFunctions()" because the return value of "net.minecraft.commands.CommandSourceStack.getServer()" is null
        at net.minecraft.commands.arguments.item.FunctionArgument.getFunction(FunctionArgument.java:71)
        at net.minecraft.commands.arguments.item.FunctionArgument$2.create(FunctionArgument.java:55)
        at net.minecraft.commands.arguments.item.FunctionArgument.getFunctions(FunctionArgument.java:84)
        at net.minecraft.server.commands.DebugCommand$TraceCustomExecutor.runGuarded(DebugCommand.java:108)
        at net.minecraft.server.commands.DebugCommand$TraceCustomExecutor.runGuarded(DebugCommand.java:96)
        at net.minecraft.commands.execution.CustomCommandExecutor$WithErrorHandling.run(CustomCommandExecutor.java:24)
        at net.minecraft.commands.execution.CustomCommandExecutor$WithErrorHandling.run(CustomCommandExecutor.java:20)
        at net.minecraft.commands.execution.tasks.BuildContexts.execute(BuildContexts.java:114)
        at net.minecraft.commands.execution.tasks.BuildContexts$Unbound.execute(BuildContexts.java:156)
        at net.minecraft.commands.execution.tasks.BuildContexts$Unbound.execute(BuildContexts.java:148)
        at net.minecraft.commands.execution.UnboundEntryAction.lambda$bind$0(UnboundEntryAction.java:8)
        at net.minecraft.commands.execution.CommandQueueEntry.execute(CommandQueueEntry.java:8)
        at net.minecraft.commands.execution.ExecutionContext.runCommandQueue(ExecutionContext.java:106)
        at net.minecraft.commands.Commands.executeCommandInContext(Commands.java:430)
        at net.minecraft.commands.Commands.performCommand(Commands.java:362)
        at net.minecraft.commands.Commands.performPrefixedCommand(Commands.java:348)
        at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:449)
        at net.minecraft.server.dedicated.DedicatedServer.tickConnection(DedicatedServer.java:439)
        at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:1155)
        at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1015)
        at net.minecraft.server.dedicated.DedicatedServer.tickServer(DedicatedServer.java:318)
        at net.minecraft.server.MinecraftServer.processPacketsAndTick(MinecraftServer.java:1048)
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:770)
        at net.minecraft.server.MinecraftServer.lambda$spin$2(MinecraftServer.java:300)
        at java.base/java.lang.Thread.run(Thread.java:1583)

Attachments

Comments 1

[Mod] ManosSef

(Unassigned)

Community Consensus

Platform

Low

Commands, Debug

1.21.4, 1.21.9, 1.21.10 Release Candidate 1, 1.21.11

Retrieved