From 73804d45dfe8260efc9cb21ffb046bf0957eea9b Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Fri, 11 Oct 2013 02:49:07 +0200 Subject: [PATCH] Make UnknownHostException more low-key. They are to be expected. Whenever the update procedure is ongoing, and the server temporarily lost connectivity to the internet (or more likely, dev.bukkit.org is down), a huge exception log will be printed in the console. See ticket 134 for a real life example. This is completely out of propotion to the problem at hand (connection problems), so we will replace the error log with a simple warning message. --- .../comphenix/protocol/CommandProtocol.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java index 33328aeb..ef0a3f82 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java @@ -19,6 +19,7 @@ package com.comphenix.protocol; import java.io.File; import java.io.IOException; +import java.net.UnknownHostException; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -45,7 +46,7 @@ class CommandProtocol extends CommandBase { */ public static final String NAME = "protocol"; - public static final ReportType REPORT_HTTP_ERROR = new ReportType("Http error: %s"); + public static final ReportType REPORT_NETWORK_ERROR = new ReportType("Network error: %s"); public static final ReportType REPORT_CANNOT_CHECK_FOR_UPDATES = new ReportType("Cannot check updates for ProtocolLib."); public static final ReportType REPORT_CANNOT_UPDATE_PLUGIN = new ReportType("Cannot update ProtocolLib."); @@ -87,9 +88,9 @@ class CommandProtocol extends CommandBase { UpdateResult result = updater.update(UpdateType.NO_DOWNLOAD, true); sender.sendMessage(ChatColor.BLUE + "[ProtocolLib] " + result.toString()); } catch (Exception e) { - if (isHttpError(e)) { + if (isNetworkError(e)) { getReporter().reportWarning(CommandProtocol.this, - Report.newBuilder(REPORT_HTTP_ERROR).messageParam(e.getCause().getMessage()) + Report.newBuilder(REPORT_NETWORK_ERROR).messageParam(e.getCause().getMessage()) ); } else { getReporter().reportDetailed(CommandProtocol.this, Report.newBuilder(REPORT_CANNOT_CHECK_FOR_UPDATES).error(e).callerParam(sender)); @@ -110,9 +111,9 @@ class CommandProtocol extends CommandBase { UpdateResult result = updater.update(UpdateType.DEFAULT, true); sender.sendMessage(ChatColor.BLUE + "[ProtocolLib] " + result.toString()); } catch (Exception e) { - if (isHttpError(e)) { + if (isNetworkError(e)) { getReporter().reportWarning(CommandProtocol.this, - Report.newBuilder(REPORT_HTTP_ERROR).messageParam(e.getCause().getMessage()) + Report.newBuilder(REPORT_NETWORK_ERROR).messageParam(e.getCause().getMessage()) ); } else { getReporter().reportDetailed(CommandProtocol.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(e).callerParam(sender)); @@ -173,10 +174,13 @@ class CommandProtocol extends CommandBase { } } - private boolean isHttpError(Exception e) { + private boolean isNetworkError(Exception e) { Throwable cause = e.getCause(); - if (cause instanceof IOException) { + if (cause instanceof UnknownHostException) { + // These are always network problems + return true; + } if (cause instanceof IOException) { // Thanks for making the message a part of the API ... return cause.getMessage().contains("HTTP response"); } else {