Don't catch unexpected exceptions during command execution

This commit is contained in:
Dylan K. Taylor 2018-11-04 23:11:22 +00:00
parent 755db3dac8
commit 1634dd62e3
2 changed files with 2 additions and 14 deletions

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace pocketmine\command; namespace pocketmine\command;
use pocketmine\lang\TranslationContainer;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -49,11 +48,6 @@ class FormattedCommandAlias extends Command{
$commands[] = $this->buildCommand($formatString, $args); $commands[] = $this->buildCommand($formatString, $args);
}catch(\InvalidArgumentException $e){ }catch(\InvalidArgumentException $e){
$sender->sendMessage(TextFormat::RED . $e->getMessage()); $sender->sendMessage(TextFormat::RED . $e->getMessage());
return false;
}catch(\Throwable $e){
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.exception"));
$sender->getServer()->getLogger()->logException($e);
return false; return false;
} }
} }

View File

@ -65,9 +65,7 @@ use pocketmine\command\defaults\VanillaCommand;
use pocketmine\command\defaults\VersionCommand; use pocketmine\command\defaults\VersionCommand;
use pocketmine\command\defaults\WhitelistCommand; use pocketmine\command\defaults\WhitelistCommand;
use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\TextFormat;
class SimpleCommandMap implements CommandMap{ class SimpleCommandMap implements CommandMap{
@ -258,13 +256,9 @@ class SimpleCommandMap implements CommandMap{
$target->execute($sender, $sentCommandLabel, $args); $target->execute($sender, $sentCommandLabel, $args);
}catch(InvalidCommandSyntaxException $e){ }catch(InvalidCommandSyntaxException $e){
$sender->sendMessage($this->server->getLanguage()->translateString("commands.generic.usage", [$target->getUsage()])); $sender->sendMessage($this->server->getLanguage()->translateString("commands.generic.usage", [$target->getUsage()]));
}catch(\Throwable $e){ }finally{
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.exception"));
$this->server->getLogger()->critical($this->server->getLanguage()->translateString("pocketmine.command.exception", [$commandLine, (string) $target, $e->getMessage()]));
$sender->getServer()->getLogger()->logException($e);
}
$target->timings->stopTiming(); $target->timings->stopTiming();
}
return true; return true;
} }