Archiviert
13
0

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.
Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-10-11 02:49:07 +02:00
Ursprung 8a4982e169
Commit 73804d45df

Datei anzeigen

@ -19,6 +19,7 @@ package com.comphenix.protocol;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -45,7 +46,7 @@ class CommandProtocol extends CommandBase {
*/ */
public static final String NAME = "protocol"; 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_CHECK_FOR_UPDATES = new ReportType("Cannot check updates for ProtocolLib.");
public static final ReportType REPORT_CANNOT_UPDATE_PLUGIN = new ReportType("Cannot update 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); UpdateResult result = updater.update(UpdateType.NO_DOWNLOAD, true);
sender.sendMessage(ChatColor.BLUE + "[ProtocolLib] " + result.toString()); sender.sendMessage(ChatColor.BLUE + "[ProtocolLib] " + result.toString());
} catch (Exception e) { } catch (Exception e) {
if (isHttpError(e)) { if (isNetworkError(e)) {
getReporter().reportWarning(CommandProtocol.this, getReporter().reportWarning(CommandProtocol.this,
Report.newBuilder(REPORT_HTTP_ERROR).messageParam(e.getCause().getMessage()) Report.newBuilder(REPORT_NETWORK_ERROR).messageParam(e.getCause().getMessage())
); );
} else { } else {
getReporter().reportDetailed(CommandProtocol.this, Report.newBuilder(REPORT_CANNOT_CHECK_FOR_UPDATES).error(e).callerParam(sender)); 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); UpdateResult result = updater.update(UpdateType.DEFAULT, true);
sender.sendMessage(ChatColor.BLUE + "[ProtocolLib] " + result.toString()); sender.sendMessage(ChatColor.BLUE + "[ProtocolLib] " + result.toString());
} catch (Exception e) { } catch (Exception e) {
if (isHttpError(e)) { if (isNetworkError(e)) {
getReporter().reportWarning(CommandProtocol.this, getReporter().reportWarning(CommandProtocol.this,
Report.newBuilder(REPORT_HTTP_ERROR).messageParam(e.getCause().getMessage()) Report.newBuilder(REPORT_NETWORK_ERROR).messageParam(e.getCause().getMessage())
); );
} else { } else {
getReporter().reportDetailed(CommandProtocol.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(e).callerParam(sender)); 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(); 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 ... // Thanks for making the message a part of the API ...
return cause.getMessage().contains("HTTP response"); return cause.getMessage().contains("HTTP response");
} else { } else {