Skip to content

Commit

Permalink
log exceptions from commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Faithcaio committed May 23, 2024
1 parent 387bdb9 commit 0d3d9ec
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import org.spongepowered.common.event.tracking.phase.general.CommandPhaseContext;
import org.spongepowered.common.event.tracking.phase.general.GeneralPhase;

import java.util.Optional;

@Mixin(ExecuteCommand.class)
public abstract class ExecuteCommandMixin {

Expand Down Expand Up @@ -104,6 +106,14 @@ public abstract class ExecuteCommandMixin {
));
return result;
}
catch (Exception e) {
var owner = Optional.ofNullable(mapping)
.flatMap(CommandMapping::plugin)
.map(pc -> pc.metadata().id())
.orElse("UNKNOWN");
SpongeCommon.logger().error("Could not execute command '{}' from plugin '{}'", this.commandInput, owner, e);
throw e;
}
}
}
}

0 comments on commit 0d3d9ec

Please sign in to comment.