testserver/patches/server/0053-Add-exception-reportin...

265 lines
15 KiB
Diff
Raw Normal View History

2021-06-11 12:02:28 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Joseph Hirschfeld <joe@ibj.io>
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/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
2021-06-17 21:39:36 +00:00
index 3b1565309165e10b147d08b8245ea0bce50dc3c2..4ebb839076a2d1f5e2acc6d5a8dfcf3545b37721 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
2021-06-12 00:57:04 +00:00
@@ -825,6 +825,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 12:02:28 +00:00
return true;
} catch (Exception exception) {
ChunkMap.LOGGER.error("Failed to save chunk {},{}", chunkcoordintpair.x, chunkcoordintpair.z, exception);
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(exception); // Paper
return false;
}
}
diff --git a/src/main/java/net/minecraft/server/players/OldUsersConverter.java b/src/main/java/net/minecraft/server/players/OldUsersConverter.java
2021-06-17 21:39:36 +00:00
index 741bc569617c66f90ded58a28dd3ad0e4e8b1e8c..8e27b43e2f6ce4d7f5007fe02db1722e73c30a58 100644
2021-06-11 12:02:28 +00:00
--- 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;
2021-06-12 00:57:04 +00:00
@@ -362,6 +363,7 @@ public class OldUsersConverter {
2021-06-11 12:02:28 +00:00
root = NbtIo.readCompressed(new java.io.FileInputStream(file5));
} catch (Exception exception) {
exception.printStackTrace();
+ ServerInternalException.reportInternalException(exception); // Paper
}
if (root != null) {
2021-06-12 00:57:04 +00:00
@@ -375,6 +377,7 @@ public class OldUsersConverter {
2021-06-11 12:02:28 +00:00
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
2021-06-12 00:57:04 +00:00
index 08c5f6fd1a307c89cf8365f56314a0c6d3e89e4b..26e0f03f2e736ed6ba86e2510a7962deee180ef3 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/entity/ai/village/VillageSiege.java
+++ b/src/main/java/net/minecraft/world/entity/ai/village/VillageSiege.java
@@ -1,5 +1,7 @@
package net.minecraft.world.entity.ai.village;
+import com.destroystokyo.paper.exception.ServerInternalException;
+
import java.util.Iterator;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
@@ -119,6 +121,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);
+ 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
2021-06-17 21:39:36 +00:00
index da8e6f5b48a83ca4178c0de439200b7952f409d9..969a5ed2484036103834dc23b57b33c11896d72f 100644
2021-06-11 12:02:28 +00:00
--- 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;
2021-06-17 21:39:36 +00:00
@@ -729,8 +734,10 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 12:02:28 +00:00
tickConsumer.accept(entity);
} catch (Throwable throwable) {
// Paper start - Prevent tile entity and entity crashes
- System.err.println("Entity threw exception at " + entity.level.getWorld().getName() + ":" + entity.getX() + "," + entity.getY() + "," + entity.getZ());
+ String msg = "Entity threw exception at " + entity.level.getWorld().getName() + ":" + entity.getX() + "," + entity.getY() + "," + entity.getZ();
+ System.err.println(msg);
throwable.printStackTrace();
+ getCraftServer().getPluginManager().callEvent(new ServerExceptionEvent(new ServerInternalException(msg, throwable)));
2021-06-12 00:57:04 +00:00
entity.discard();
2021-06-11 12:02:28 +00:00
// Paper end
2021-06-12 00:57:04 +00:00
}
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
2021-06-12 00:57:04 +00:00
index b4a7776ba9486bbca42ffb596c8a8bcdf6471ce3..59fae60116167baf989e85596334824e9004e6fb 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java
+++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
2021-06-12 00:57:04 +00:00
@@ -308,6 +308,7 @@ public final class NaturalSpawner {
2021-06-11 12:02:28 +00:00
}
} catch (Exception exception) {
NaturalSpawner.LOGGER.warn("Failed to create mob", exception);
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(exception); // Paper
return null;
}
}
2021-06-12 00:57:04 +00:00
@@ -410,6 +411,7 @@ public final class NaturalSpawner {
entity = biomesettingsmobs_c.type.create((Level) world.getLevel());
} catch (Exception exception) {
NaturalSpawner.LOGGER.warn("Failed to create mob", exception);
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(exception); // Paper
continue;
}
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
2021-06-17 21:39:36 +00:00
index 21f613b8d7785b996866b5059f3cb1bc87533d2e..249f39bc0c5820e313cad7813bd1087cb2e09ed6 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
2021-06-12 00:57:04 +00:00
@@ -1,6 +1,7 @@
2021-06-11 12:02:28 +00:00
package net.minecraft.world.level.chunk;
2021-06-12 00:57:04 +00:00
import com.google.common.collect.ImmutableList;
2021-06-11 12:02:28 +00:00
+import com.destroystokyo.paper.exception.ServerInternalException;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
2021-06-12 00:57:04 +00:00
import com.google.common.collect.UnmodifiableIterator;
@@ -615,10 +616,15 @@ public class LevelChunk implements ChunkAccess {
2021-06-12 06:02:49 +00:00
this.removeBlockEntity(blockEntity.getBlockPos());
2021-06-11 12:02:28 +00:00
// Paper end
} else {
- System.out.println("Attempted to place a tile entity (" + blockEntity + ") at " + blockEntity.getBlockPos().getX() + "," + blockEntity.getBlockPos().getY() + "," + blockEntity.getBlockPos().getZ()
2021-06-12 00:57:04 +00:00
- + " (" + this.getBlockState(blockposition) + ") where there was no entity tile!");
2021-06-11 12:02:28 +00:00
- System.out.println("Chunk coordinates: " + (this.chunkPos.x * 16) + "," + (this.chunkPos.z * 16));
- new Exception().printStackTrace();
+ // Paper start
+ ServerInternalException e = new ServerInternalException(
2021-06-12 00:57:04 +00:00
+ "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));
2021-06-11 12:02:28 +00:00
+ e.printStackTrace();
+ ServerInternalException.reportInternalException(e);
+ // Paper end
// CraftBukkit end
}
}
2021-06-12 00:57:04 +00:00
@@ -1242,8 +1248,10 @@ public class LevelChunk implements ChunkAccess {
gameprofilerfiller.pop();
} catch (Throwable throwable) {
// Paper start - Prevent tile entity and entity crashes
- System.err.println("TileEntity threw exception at " + LevelChunk.this.getLevel().getWorld().getName() + ":" + this.getPos().getX() + "," + this.getPos().getY() + "," + this.getPos().getZ());
+ String msg = "TileEntity threw exception at " + LevelChunk.this.getLevel().getWorld().getName() + ":" + this.getPos().getX() + "," + this.getPos().getY() + "," + this.getPos().getZ();
+ System.err.println(msg);
throwable.printStackTrace();
+ 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
2021-06-11 12:02:28 +00:00
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
2021-06-17 21:39:36 +00:00
index 1441888430687b9de2a67f21ed426f16d5b30538..f514c29e64a9c7a66ff4edd5ba8c2a3dfbba2ad9 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
2021-06-17 21:39:36 +00:00
@@ -277,6 +277,7 @@ public class RegionFile implements AutoCloseable {
2021-06-11 12:02:28 +00:00
return true;
}
} catch (IOException ioexception) {
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(ioexception); // Paper
return false;
}
}
2021-06-17 21:39:36 +00:00
@@ -358,6 +359,7 @@ public class RegionFile implements AutoCloseable {
2021-06-12 00:57:04 +00:00
((java.nio.Buffer) bytebuffer).position(5); // CraftBukkit - decompile error
2021-06-11 12:02:28 +00:00
filechannel.write(bytebuffer);
2021-06-12 00:57:04 +00:00
} catch (Throwable throwable) {
2021-06-11 12:02:28 +00:00
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(throwable); // Paper
if (filechannel != null) {
2021-06-12 00:57:04 +00:00
try {
filechannel.close();
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java b/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java
2021-06-12 00:57:04 +00:00
index 2fdb313e8eaed868c36f68c9b7f6a6f9f4864575..c8ed0673ff819cb88d0ee6f53f2a2b9b46b203d4 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java
+++ b/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java
2021-06-12 00:57:04 +00:00
@@ -120,6 +120,7 @@ public class DimensionDataStorage {
pushbackInputStream.close();
} catch (Throwable var15) {
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(var15); // Paper
try {
fileInputStream.close();
} catch (Throwable var10) {
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
2021-06-12 00:57:04 +00:00
index e6a09ed5db245eaecd787503dbfb1ef5fea5bb70..0735c2fe139ce8d47a04fdba045fe462492723eb 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
@@ -16,6 +16,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.logging.Level;
+import com.destroystokyo.paper.ServerSchedulerReportingWrapper;
+import com.destroystokyo.paper.event.server.ServerExceptionEvent;
+import com.destroystokyo.paper.exception.ServerSchedulerException;
import org.apache.commons.lang.Validate;
import org.bukkit.plugin.IllegalPluginAccessException;
import org.bukkit.plugin.Plugin;
@@ -419,6 +422,8 @@ public class CraftScheduler implements BukkitScheduler {
msg,
throwable);
}
+ org.bukkit.Bukkit.getServer().getPluginManager().callEvent(
+ new ServerExceptionEvent(new ServerSchedulerException(msg, throwable, task)));
// Paper end
} finally {
2021-06-12 00:57:04 +00:00
this.currentTask = null;
2021-06-11 12:02:28 +00:00
@@ -426,7 +431,7 @@ public class CraftScheduler implements BukkitScheduler {
2021-06-12 00:57:04 +00:00
this.parsePending();
2021-06-11 12:02:28 +00:00
} else {
2021-06-12 00:57:04 +00:00
this.debugTail = this.debugTail.setNext(new CraftAsyncDebugger(currentTick + CraftScheduler.RECENT_TICKS, task.getOwner(), task.getTaskClass()));
- this.executor.execute(task);
+ this.executor.execute(new ServerSchedulerReportingWrapper(task)); // Paper
2021-06-11 12:02:28 +00:00
// 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)
}