13
0
geforkt von Mirrors/Velocity

Swallow and more usefully log exceptions in scheduler task running.

Dieser Commit ist enthalten in:
Andrew Steinborn 2021-01-09 16:39:38 -05:00
Ursprung ba1c1eef64
Commit 567a3b2365

Datei anzeigen

@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps; import com.google.common.collect.Multimaps;
import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.PluginManager; import com.velocitypowered.api.plugin.PluginManager;
import com.velocitypowered.api.scheduler.ScheduledTask; import com.velocitypowered.api.scheduler.ScheduledTask;
import com.velocitypowered.api.scheduler.Scheduler; import com.velocitypowered.api.scheduler.Scheduler;
@ -183,8 +184,18 @@ public class VelocityScheduler implements Scheduler {
currentTaskThread = Thread.currentThread(); currentTaskThread = Thread.currentThread();
try { try {
runnable.run(); runnable.run();
} catch (Exception e) { } catch (Throwable e) {
Log.logger.error("Exception in task {} by plugin {}", runnable, plugin, e); //noinspection ConstantConditions
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
} else {
String friendlyPluginName = pluginManager.fromInstance(plugin)
.map(container -> container.getDescription().getName()
.orElse(container.getDescription().getId()))
.orElse("UNKNOWN");
Log.logger.error("Exception in task {} by plugin {}", runnable, friendlyPluginName,
e);
}
} finally { } finally {
if (repeat == 0) { if (repeat == 0) {
onFinish(); onFinish();