diff options
author | Noah van der Aa <[email protected]> | 2023-09-21 22:14:58 +0200 |
---|---|---|
committer | Noah van der Aa <[email protected]> | 2023-09-21 22:14:58 +0200 |
commit | 91671751e7ceff11d456ce337fcdec709b0791a1 (patch) | |
tree | a8c49db22ec99356546e189b0ce83c7d554ded9b /patches/server/0059-Add-exception-reporting-event.patch | |
parent | 20253f478fb4b1178de144f0fe9bbac7db9e04a8 (diff) | |
download | Paper-91671751e7ceff11d456ce337fcdec709b0791a1.tar.gz Paper-91671751e7ceff11d456ce337fcdec709b0791a1.zip |
more more more work
Diffstat (limited to 'patches/server/0059-Add-exception-reporting-event.patch')
-rw-r--r-- | patches/server/0059-Add-exception-reporting-event.patch | 215 |
1 files changed, 215 insertions, 0 deletions
diff --git a/patches/server/0059-Add-exception-reporting-event.patch b/patches/server/0059-Add-exception-reporting-event.patch new file mode 100644 index 0000000000..68114b68e1 --- /dev/null +++ b/patches/server/0059-Add-exception-reporting-event.patch @@ -0,0 +1,215 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Joseph Hirschfeld <[email protected]> +Date: Thu, 3 Mar 2016 03:15:41 -0600 +Subject: [PATCH] Add exception reporting event + + +diff --git a/src/main/java/com/destroystokyo/paper/ServerSchedulerReportingWrapper.java b/src/main/java/com/destroystokyo/paper/ServerSchedulerReportingWrapper.java +new file mode 100644 +index 0000000000000000000000000000000000000000..f699ce18ca044f813e194ef2786b7ea853ea86e7 +--- /dev/null ++++ b/src/main/java/com/destroystokyo/paper/ServerSchedulerReportingWrapper.java +@@ -0,0 +1,38 @@ ++package com.destroystokyo.paper; ++ ++import com.google.common.base.Preconditions; ++import org.bukkit.craftbukkit.scheduler.CraftTask; ++import com.destroystokyo.paper.event.server.ServerExceptionEvent; ++import com.destroystokyo.paper.exception.ServerSchedulerException; ++ ++/** ++ * Reporting wrapper to catch exceptions not natively ++ */ ++public class ServerSchedulerReportingWrapper implements Runnable { ++ ++ private final CraftTask internalTask; ++ ++ public ServerSchedulerReportingWrapper(CraftTask internalTask) { ++ this.internalTask = Preconditions.checkNotNull(internalTask, "internalTask"); ++ } ++ ++ @Override ++ public void run() { ++ try { ++ internalTask.run(); ++ } catch (RuntimeException e) { ++ internalTask.getOwner().getServer().getPluginManager().callEvent( ++ new ServerExceptionEvent(new ServerSchedulerException(e, internalTask)) ++ ); ++ throw e; ++ } catch (Throwable t) { ++ internalTask.getOwner().getServer().getPluginManager().callEvent( ++ new ServerExceptionEvent(new ServerSchedulerException(t, internalTask)) ++ ); //Do not rethrow, since it is not permitted with Runnable#run ++ } ++ } ++ ++ public CraftTask getInternalTask() { ++ return internalTask; ++ } ++} +diff --git a/src/main/java/net/minecraft/server/players/OldUsersConverter.java b/src/main/java/net/minecraft/server/players/OldUsersConverter.java +index 0650b1eee2ae8caa5268f4df82f740440ce16fdf..0214830d9bc98b8d435ff11f40df65596980cf77 100644 +--- a/src/main/java/net/minecraft/server/players/OldUsersConverter.java ++++ b/src/main/java/net/minecraft/server/players/OldUsersConverter.java +@@ -1,5 +1,6 @@ + package net.minecraft.server.players; + ++import com.destroystokyo.paper.exception.ServerInternalException; + import com.google.common.collect.Lists; + import com.google.common.collect.Maps; + import com.google.common.io.Files; +@@ -358,6 +359,7 @@ public class OldUsersConverter { + root = NbtIo.readCompressed(new java.io.FileInputStream(file5)); + } catch (Exception exception) { + exception.printStackTrace(); ++ ServerInternalException.reportInternalException(exception); // Paper + } + + if (root != null) { +@@ -371,6 +373,7 @@ public class OldUsersConverter { + NbtIo.writeCompressed(root, new java.io.FileOutputStream(file2)); + } catch (Exception exception) { + exception.printStackTrace(); ++ ServerInternalException.reportInternalException(exception); // Paper + } + } + // CraftBukkit end +diff --git a/src/main/java/net/minecraft/world/entity/ai/village/VillageSiege.java b/src/main/java/net/minecraft/world/entity/ai/village/VillageSiege.java +index c6fb4c33d7ea52b88d8fc0d90748cbab7387c565..fed09b886f4fa0006d160e5f2abb00dfee45434d 100644 +--- a/src/main/java/net/minecraft/world/entity/ai/village/VillageSiege.java ++++ b/src/main/java/net/minecraft/world/entity/ai/village/VillageSiege.java +@@ -118,6 +118,7 @@ public class VillageSiege implements CustomSpawner { + entityzombie.finalizeSpawn(world, world.getCurrentDifficultyAt(entityzombie.blockPosition()), MobSpawnType.EVENT, (SpawnGroupData) null, (CompoundTag) null); + } catch (Exception exception) { + VillageSiege.LOGGER.warn("Failed to create zombie for village siege at {}", vec3d, exception); ++ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(exception); // Paper + return; + } + +diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java +index 42e81640354c2679570823347b28ee1155e7a00e..a7fb12648c2e655e191d8c805753ae0c05421d17 100644 +--- a/src/main/java/net/minecraft/world/level/Level.java ++++ b/src/main/java/net/minecraft/world/level/Level.java +@@ -1,5 +1,10 @@ + package net.minecraft.world.level; + ++import co.aikar.timings.Timing; ++import co.aikar.timings.Timings; ++import com.destroystokyo.paper.event.server.ServerExceptionEvent; ++import com.destroystokyo.paper.exception.ServerInternalException; ++import com.google.common.base.MoreObjects; + import com.google.common.collect.Lists; + import com.mojang.serialization.Codec; + import java.io.IOException; +@@ -725,6 +730,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { + // Paper start - Prevent tile entity and entity crashes + final String msg = String.format("Entity threw exception at %s:%s,%s,%s", entity.level().getWorld().getName(), entity.getX(), entity.getY(), entity.getZ()); + MinecraftServer.LOGGER.error(msg, throwable); ++ getCraftServer().getPluginManager().callEvent(new ServerExceptionEvent(new ServerInternalException(msg, throwable))); + entity.discard(); + // Paper end + } +diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java +index 5d65baba605dd83e5f74d526aeda36d8ede8c014..92e76dd39dc3575e9466031dd799080a98ad8b8d 100644 +--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java ++++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java +@@ -291,6 +291,7 @@ public final class NaturalSpawner { + NaturalSpawner.LOGGER.warn("Can't spawn entity of type: {}", BuiltInRegistries.ENTITY_TYPE.getKey(type)); + } catch (Exception exception) { + NaturalSpawner.LOGGER.warn("Failed to create mob", exception); ++ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(exception); // Paper + } + + return null; +@@ -404,6 +405,7 @@ public final class NaturalSpawner { + entity = biomesettingsmobs_c.type.create(world.getLevel()); + } catch (Exception exception) { + NaturalSpawner.LOGGER.warn("Failed to create mob", exception); ++ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(exception); // Paper + continue; + } + +diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java +index 28ae0792c6b83580369937673f475f79b1c19576..0b246935d0ad3f8a78e86f0e60f53a05efda8355 100644 +--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java ++++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java +@@ -1,6 +1,7 @@ + package net.minecraft.world.level.chunk; + + import com.google.common.collect.ImmutableList; ++import com.destroystokyo.paper.exception.ServerInternalException; + import com.google.common.collect.Maps; + import com.google.common.collect.UnmodifiableIterator; + import com.mojang.logging.LogUtils; +@@ -568,10 +569,16 @@ public class LevelChunk extends ChunkAccess { + + // CraftBukkit start + } else { +- System.out.println("Attempted to place a tile entity (" + blockEntity + ") at " + blockEntity.getBlockPos().getX() + "," + blockEntity.getBlockPos().getY() + "," + blockEntity.getBlockPos().getZ() +- + " (" + this.getBlockState(blockposition) + ") where there was no entity tile!"); +- System.out.println("Chunk coordinates: " + (this.chunkPos.x * 16) + "," + (this.chunkPos.z * 16)); +- new Exception().printStackTrace(); ++ // Paper start ++ ServerInternalException e = new ServerInternalException( ++ "Attempted to place a tile entity (" + blockEntity + ") at " + blockEntity.getBlockPos().getX() + "," ++ + blockEntity.getBlockPos().getY() + "," + blockEntity.getBlockPos().getZ() ++ + " (" + getBlockState(blockposition) + ") where there was no entity tile!\n" + ++ "Chunk coordinates: " + (this.chunkPos.x * 16) + "," + (this.chunkPos.z * 16) + ++ "\nWorld: " + level.getLevel().dimension().location()); ++ e.printStackTrace(); ++ ServerInternalException.reportInternalException(e); ++ // Paper end + // CraftBukkit end + } + } +@@ -1060,6 +1067,7 @@ public class LevelChunk extends ChunkAccess { + // Paper start - Prevent tile entity and entity crashes + final String msg = String.format("BlockEntity threw exception at %s:%s,%s,%s", LevelChunk.this.getLevel().getWorld().getName(), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ()); + net.minecraft.server.MinecraftServer.LOGGER.error(msg, throwable); ++ net.minecraft.world.level.chunk.LevelChunk.this.level.getCraftServer().getPluginManager().callEvent(new com.destroystokyo.paper.event.server.ServerExceptionEvent(new ServerInternalException(msg, throwable))); + LevelChunk.this.removeBlockEntity(this.getPos()); + // Paper end + // Spigot start +diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java +index d9daf07132c46548964a75588b69d7a74680e917..67a2f3c02aa4983b3ec2df073821190ddb36543c 100644 +--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java ++++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java +@@ -274,6 +274,7 @@ public class RegionFile implements AutoCloseable { + return true; + } + } catch (IOException ioexception) { ++ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(ioexception); // Paper + return false; + } + } +@@ -355,6 +356,7 @@ public class RegionFile implements AutoCloseable { + ((java.nio.Buffer) buf).position(5); // CraftBukkit - decompile error + filechannel.write(buf); + } catch (Throwable throwable) { ++ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(throwable); // Paper + if (filechannel != null) { + try { + filechannel.close(); +diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java +index fcbf32a233c240dd45f75ee736bd102ce9f79332..833240d2a4936343710a60876a66d01112e15a2c 100644 +--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java ++++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java +@@ -434,6 +434,8 @@ public class CraftScheduler implements BukkitScheduler { + msg, + throwable); + } ++ org.bukkit.Bukkit.getServer().getPluginManager().callEvent( ++ new com.destroystokyo.paper.event.server.ServerExceptionEvent(new com.destroystokyo.paper.exception.ServerSchedulerException(msg, throwable, task))); + // Paper end + } finally { + this.currentTask = null; +@@ -441,7 +443,7 @@ public class CraftScheduler implements BukkitScheduler { + this.parsePending(); + } else { + this.debugTail = this.debugTail.setNext(new CraftAsyncDebugger(currentTick + CraftScheduler.RECENT_TICKS, task.getOwner(), task.getTaskClass())); +- this.executor.execute(task); ++ this.executor.execute(new com.destroystokyo.paper.ServerSchedulerReportingWrapper(task)); // Paper + // We don't need to parse pending + // (async tasks must live with race-conditions if they attempt to cancel between these few lines of code) + } |