LevelDB: make unknown block errors way less annoying

these would previously generate a new line for every error.
since errors are often repeated for different offsets (e.g. different states of the same block),
we can save a lot of spam by deduplicating them and telling which offsets the errors occurred in.
This commit is contained in:
Dylan K. Taylor 2025-05-28 22:03:29 +01:00
parent baafaed362
commit 035d2dec23
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -36,6 +36,7 @@ use pocketmine\nbt\TreeRoot;
use pocketmine\utils\Binary; use pocketmine\utils\Binary;
use pocketmine\utils\BinaryDataException; use pocketmine\utils\BinaryDataException;
use pocketmine\utils\BinaryStream; use pocketmine\utils\BinaryStream;
use pocketmine\utils\Utils;
use pocketmine\VersionInfo; use pocketmine\VersionInfo;
use pocketmine\world\format\Chunk; use pocketmine\world\format\Chunk;
use pocketmine\world\format\io\BaseWorldProvider; use pocketmine\world\format\io\BaseWorldProvider;
@ -204,23 +205,29 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
$blockStateData = $this->blockDataUpgrader->upgradeBlockStateNbt($blockStateNbt); $blockStateData = $this->blockDataUpgrader->upgradeBlockStateNbt($blockStateNbt);
}catch(BlockStateDeserializeException $e){ }catch(BlockStateDeserializeException $e){
//while not ideal, this is not a fatal error //while not ideal, this is not a fatal error
$blockDecodeErrors[] = "Palette offset $i / Upgrade error: " . $e->getMessage() . ", NBT: " . $blockStateNbt->toString(); $errorMessage = "Upgrade error: " . $e->getMessage() . ", NBT: " . $blockStateNbt->toString();
$blockDecodeErrors[$errorMessage][] = $i;
$palette[] = $this->blockStateDeserializer->deserialize(GlobalBlockStateHandlers::getUnknownBlockStateData()); $palette[] = $this->blockStateDeserializer->deserialize(GlobalBlockStateHandlers::getUnknownBlockStateData());
continue; continue;
} }
try{ try{
$palette[] = $this->blockStateDeserializer->deserialize($blockStateData); $palette[] = $this->blockStateDeserializer->deserialize($blockStateData);
}catch(UnsupportedBlockStateException $e){ }catch(UnsupportedBlockStateException $e){
$blockDecodeErrors[] = "Palette offset $i / " . $e->getMessage(); $blockDecodeErrors[$e->getMessage()][] = $i;
$palette[] = $this->blockStateDeserializer->deserialize(GlobalBlockStateHandlers::getUnknownBlockStateData()); $palette[] = $this->blockStateDeserializer->deserialize(GlobalBlockStateHandlers::getUnknownBlockStateData());
}catch(BlockStateDeserializeException $e){ }catch(BlockStateDeserializeException $e){
$blockDecodeErrors[] = "Palette offset $i / Deserialize error: " . $e->getMessage() . ", NBT: " . $blockStateNbt->toString(); $errorMessage = "Deserialize error: " . $e->getMessage() . ", NBT: " . $blockStateNbt->toString();
$blockDecodeErrors[$errorMessage][] = $i;
$palette[] = $this->blockStateDeserializer->deserialize(GlobalBlockStateHandlers::getUnknownBlockStateData()); $palette[] = $this->blockStateDeserializer->deserialize(GlobalBlockStateHandlers::getUnknownBlockStateData());
} }
} }
if(count($blockDecodeErrors) > 0){ if(count($blockDecodeErrors) > 0){
$logger->error("Errors decoding blocks:\n - " . implode("\n - ", $blockDecodeErrors)); $finalErrors = [];
foreach(Utils::promoteKeys($blockDecodeErrors) as $errorMessage => $paletteOffsets){
$finalErrors[] = "$errorMessage (palette offsets: " . implode(", ", $paletteOffsets) . ")";
}
$logger->error("Errors decoding blocks:\n - " . implode("\n - ", $finalErrors));
} }
//TODO: exceptions //TODO: exceptions