Block: add the current class to the exception messages for block runtime data serialization

This commit is contained in:
Dylan K. Taylor 2022-07-13 19:50:35 +01:00
parent 8b2d941502
commit 20cb67461f
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -47,6 +47,7 @@ use pocketmine\world\format\Chunk;
use pocketmine\world\Position; use pocketmine\world\Position;
use pocketmine\world\World; use pocketmine\world\World;
use function count; use function count;
use function get_class;
use const PHP_INT_MAX; use const PHP_INT_MAX;
class Block{ class Block{
@ -109,7 +110,7 @@ class Block{
$this->decodeType($reader); $this->decodeType($reader);
$readBits = $reader->getOffset(); $readBits = $reader->getOffset();
if($typeBits !== $readBits){ if($typeBits !== $readBits){
throw new \LogicException("Exactly $typeBits bits of type data were provided, but $readBits were read"); throw new \LogicException(get_class($this) . ": Exactly $typeBits bits of type data were provided, but $readBits were read");
} }
} }
@ -126,7 +127,7 @@ class Block{
$this->decodeState($reader); $this->decodeState($reader);
$readBits = $reader->getOffset() - $typeBits; $readBits = $reader->getOffset() - $typeBits;
if($stateBits !== $readBits){ if($stateBits !== $readBits){
throw new \LogicException("Exactly $stateBits bits of state data were provided, but $readBits were read"); throw new \LogicException(get_class($this) . ": Exactly $stateBits bits of state data were provided, but $readBits were read");
} }
} }
@ -149,7 +150,7 @@ class Block{
$this->encodeType($writer); $this->encodeType($writer);
$writtenBits = $writer->getOffset(); $writtenBits = $writer->getOffset();
if($typeBits !== $writtenBits){ if($typeBits !== $writtenBits){
throw new \LogicException("Exactly $typeBits bits of type data were expected, but $writtenBits were written"); throw new \LogicException(get_class($this) . ": Exactly $typeBits bits of type data were expected, but $writtenBits were written");
} }
return $writer->getValue(); return $writer->getValue();
@ -168,7 +169,7 @@ class Block{
$this->encodeState($writer); $this->encodeState($writer);
$writtenBits = $writer->getOffset() - $typeBits; $writtenBits = $writer->getOffset() - $typeBits;
if($stateBits !== $writtenBits){ if($stateBits !== $writtenBits){
throw new \LogicException("Exactly $stateBits bits of state data were expected, but $writtenBits were written"); throw new \LogicException(get_class($this) . ": Exactly $stateBits bits of state data were expected, but $writtenBits were written");
} }
return $writer->getValue(); return $writer->getValue();