Author: toad
Date: 2007-02-13 23:26:05 +0000 (Tue, 13 Feb 2007)
New Revision: 11774
Modified:
trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
trunk/freenet/src/freenet/clients/http/Toadlet.java
Log:
Never go into limbo while adding a node because it caused an internal error.
Modified: trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
2007-02-13 23:11:03 UTC (rev 11773)
+++ trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
2007-02-13 23:26:05 UTC (rev 11774)
@@ -673,6 +673,9 @@
} catch (IOException e) {
this.sendErrorPage(ctx, 200, "Failed To Add
Node", "Unable to parse the given text as a node reference ("+e+"). Please try
again.");
return;
+ } catch (Throwable t) {
+ this.sendErrorPage(ctx, "Failed to Add Node:
Internal Error", "Unable to parse the given text as a node reference. Please
report the following to the developers:", t);
+ return;
}
PeerNode pn;
try {
@@ -690,6 +693,9 @@
node.addChild("br");
this.sendErrorPage(ctx, 200, "Failed To Add
Node", node);
return;
+ } catch (Throwable t) {
+ this.sendErrorPage(ctx, "Failed to Add Node:
Internal Error", "Unable to add the node reference. Please report the following
to the developers:", t);
+ return;
}
if(pn.getIdentityHash()==node.getIdentityHash()) {
this.sendErrorPage(ctx, 200, "Failed To Add
Node", "You can\u2019t add your own node to the list of remote peers.");
Modified: trunk/freenet/src/freenet/clients/http/Toadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/Toadlet.java 2007-02-13 23:11:03 UTC
(rev 11773)
+++ trunk/freenet/src/freenet/clients/http/Toadlet.java 2007-02-13 23:26:05 UTC
(rev 11774)
@@ -4,6 +4,8 @@
package freenet.clients.http;
import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.URI;
@@ -199,6 +201,38 @@
}
/**
+ * Send an error page from an exception.
+ * @param ctx The context object for this request.
+ * @param desc The title of the error page
+ * @param message The message to be sent to the user. The stack trace
will follow.
+ * @param t The Throwable which caused the error.
+ * @throws IOException If there is an error writing the reply.
+ * @throws ToadletContextClosedException If the context has already
been closed.
+ */
+ protected void sendErrorPage(ToadletContext ctx, String desc, String
message, Throwable t) throws ToadletContextClosedException, IOException {
+ HTMLNode pageNode = ctx.getPageMaker().getPageNode(desc);
+ HTMLNode contentNode =
ctx.getPageMaker().getContentNode(pageNode);
+
+ HTMLNode infobox =
contentNode.addChild(ctx.getPageMaker().getInfobox("infobox-error", desc));
+ HTMLNode infoboxContent =
ctx.getPageMaker().getContentNode(infobox);
+ infoboxContent.addChild(message);
+ infoboxContent.addChild("br");
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ t.printStackTrace(pw);
+ pw.close();
+ // FIXME what is the modern (CSS/XHTML) equivalent of <pre>?
+ infoboxContent.addChild("pre", sw.toString());
+ infoboxContent.addChild("br");
+ infoboxContent.addChild("a", "href", ".", "Return to the
previous page.");
+ infoboxContent.addChild("a", "href", "/", "Return to the main
page.");
+
+ writeReply(ctx, 500, "text/html; charset=UTF-8", desc,
pageNode.generate());
+ }
+
+
+
+ /**
* Get the client impl. DO NOT call the blocking methods on it!!
* Just use it for configuration etc.
*/