From eae9d45c8a4142541dfda7f6322784d148d4b027 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 6 Feb 2022 08:39:23 +1100 Subject: [PATCH] Provide more information in connect errors --- api/src/main/java/net/md_5/bungee/Util.java | 15 ++++++++++++++- .../main/java/net/md_5/bungee/UserConnection.java | 9 +-------- proxy/src/main/resources/messages.properties | 3 +-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/Util.java b/api/src/main/java/net/md_5/bungee/Util.java index e565c836b..1457d4c8a 100644 --- a/api/src/main/java/net/md_5/bungee/Util.java +++ b/api/src/main/java/net/md_5/bungee/Util.java @@ -88,11 +88,24 @@ public class Util * @return a string representing information about the {@link Throwable} */ public static String exception(Throwable t) + { + return exception( t, true ); + } + + /** + * Constructs a pretty one line version of a {@link Throwable}. Useful for + * debugging. + * + * @param t the {@link Throwable} to format. + * @param includeLineNumbers whether to include line numbers + * @return a string representing information about the {@link Throwable} + */ + public static String exception(Throwable t, boolean includeLineNumbers) { // TODO: We should use clear manually written exceptions StackTraceElement[] trace = t.getStackTrace(); return t.getClass().getSimpleName() + " : " + t.getMessage() - + ( ( trace.length > 0 ) ? " @ " + t.getStackTrace()[0].getClassName() + ":" + t.getStackTrace()[0].getLineNumber() : "" ); + + ( ( includeLineNumbers && trace.length > 0 ) ? " @ " + t.getStackTrace()[0].getClassName() + ":" + t.getStackTrace()[0].getLineNumber() : "" ); } public static String csv(Iterable objects) diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index bf25658ba..e481d6dfa 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -8,7 +8,6 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; -import io.netty.channel.ConnectTimeoutException; import io.netty.util.internal.PlatformDependent; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -373,13 +372,7 @@ public final class UserConnection implements ProxiedPlayer private String connectionFailMessage(Throwable cause) { - if ( cause instanceof ConnectTimeoutException ) - { - return bungee.getTranslation( "timeout" ); - } else - { - return cause.getClass().getName(); - } + return Util.exception( cause, false ); } @Override diff --git a/proxy/src/main/resources/messages.properties b/proxy/src/main/resources/messages.properties index 5890e8c90..e16cf0a81 100644 --- a/proxy/src/main/resources/messages.properties +++ b/proxy/src/main/resources/messages.properties @@ -5,9 +5,8 @@ already_connecting=\u00a7cAlready connecting to this server! command_list=\u00a7a[{0}] \u00a7e({1}): \u00a7r{2} connect_kick=\u00a7cKicked whilst connecting to {0}: {1} current_server=\u00a76You are currently connected to {0}. -fallback_kick=\u00a7cCould not connect to a default or fallback server, please try again later: {0} +fallback_kick=\u00a7cCould not connect to a default or fallback server. Incorrectly configured address/port/firewall? {0} fallback_lobby=\u00a7cCould not connect to target server, you have been moved to a fallback server. -timeout=Server not reachable (timeout). Offline? Incorrectly configured address/port/firewall? lost_connection=[Proxy] Lost connection to server. mojang_fail=Error occurred while contacting login servers, are they down? no_permission=\u00a7cYou do not have permission to execute this command!