mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
Make use of Utils::assumeNotFalse() in a bunch of places
I've stuck to only doing this in the places where I'm sure we should never get false back. Other places I'm less sure of (and I found more bugs along the way).
This commit is contained in:
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\console;
|
||||
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
use pocketmine\utils\Utils;
|
||||
use function fclose;
|
||||
use function fgets;
|
||||
use function fopen;
|
||||
@ -45,9 +45,7 @@ final class ConsoleReader{
|
||||
fclose($this->stdin);
|
||||
}
|
||||
|
||||
$stdin = fopen("php://stdin", "r");
|
||||
if($stdin === false) throw new AssumptionFailedError("Opening stdin should never fail");
|
||||
$this->stdin = $stdin;
|
||||
$this->stdin = Utils::assumeNotFalse(fopen("php://stdin", "r"), "Opening stdin should never fail");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,6 +26,7 @@ namespace pocketmine\console;
|
||||
use pocketmine\snooze\SleeperNotifier;
|
||||
use pocketmine\thread\Thread;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
use pocketmine\utils\Utils;
|
||||
use Webmozart\PathUtil\Path;
|
||||
use function base64_encode;
|
||||
use function fgets;
|
||||
@ -81,21 +82,18 @@ final class ConsoleReaderThread extends Thread{
|
||||
if($server === false){
|
||||
throw new \RuntimeException("Failed to open console reader socket server");
|
||||
}
|
||||
$address = stream_socket_get_name($server, false);
|
||||
if($address === false) throw new AssumptionFailedError("stream_socket_get_name() shouldn't return false here");
|
||||
$address = Utils::assumeNotFalse(stream_socket_get_name($server, false), "stream_socket_get_name() shouldn't return false here");
|
||||
|
||||
//Windows sucks, and likes to corrupt UTF-8 file paths when they travel to the subprocess, so we base64 encode
|
||||
//the path to avoid the problem. This is an abysmally shitty hack, but here we are :(
|
||||
$sub = proc_open(
|
||||
$sub = Utils::assumeNotFalse(proc_open(
|
||||
[PHP_BINARY, '-r', sprintf('require base64_decode("%s", true);', base64_encode(Path::join(__DIR__, 'ConsoleReaderChildProcess.php'))), $address],
|
||||
[
|
||||
2 => fopen("php://stderr", "w"),
|
||||
],
|
||||
$pipes
|
||||
);
|
||||
if($sub === false){
|
||||
throw new AssumptionFailedError("Something has gone horribly wrong");
|
||||
}
|
||||
), "Something has gone horribly wrong");
|
||||
|
||||
$client = stream_socket_accept($server, 15);
|
||||
if($client === false){
|
||||
throw new AssumptionFailedError("stream_socket_accept() returned false");
|
||||
|
Reference in New Issue
Block a user