Author: zothar
Date: 2006-07-07 17:54:23 +0000 (Fri, 07 Jul 2006)
New Revision: 9493

Modified:
   trunk/freenet/src/freenet/node/fcp/AddPeer.java
   trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
Log:
FCPify most of the error conditions in AddPeer.

Modified: trunk/freenet/src/freenet/node/fcp/AddPeer.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/AddPeer.java     2006-07-07 16:39:56 UTC 
(rev 9492)
+++ trunk/freenet/src/freenet/node/fcp/AddPeer.java     2006-07-07 17:54:23 UTC 
(rev 9493)
@@ -55,33 +55,26 @@
                                }
                                in.close();
                        } catch (MalformedURLException e) {
-                               // **FIXME** FCPify
-                               System.err.println("Did not parse: "+e);
-                               e.printStackTrace();
-                               return;
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.URL_PARSE_ERROR, "Error parsing 
ref URL <"+urlString+">: "+e.getMessage(), null);
                        } catch (IOException e) {
-                               // **FIXME** FCPify
-                               System.err.println("Did not parse: "+e);
-                               e.printStackTrace();
-                               return;
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.URL_PARSE_ERROR, "IO error while 
retrieving ref URL <"+urlString+">: "+e.getMessage(), null);
                        }
                        ref = ref.trim();
-                       if(ref == null) return;  // **FIXME** FCPify
-                       if(ref.equals("")) return;  // **FIXME** FCPify
+                       if(ref == null) {
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from URL <"+urlString+">", null);
+                       }
+                       if(ref.equals("")) {
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from URL <"+urlString+">", null);
+                       }
                        try {
                                fs = new SimpleFieldSet(ref, true);
                        } catch (IOException e) {
-                               // **FIXME** FCPify
-                               System.err.println("Did not parse: "+e);
-                               e.printStackTrace();
-                               return;
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from URL <"+urlString+">: "+e.getMessage(), null);
                        }
                } else if(fileString != null) {
                        File f = new File(fileString);
                        if(!f.isFile()) {
-                               // **FIXME** FCPify
-                               System.err.println("Not a file: "+fileString);
-                               return;
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.NOT_A_FILE_ERROR, "The given ref 
file path <"+fileString+"> is not a file", null);
                        }
                        try {
                                in = new BufferedReader(new FileReader(f));
@@ -93,41 +86,30 @@
                                }
                                in.close();
                        } catch (FileNotFoundException e) {
-                               // **FIXME** FCPify
-                               System.err.println("Did not parse: "+e);
-                               e.printStackTrace();
-                               return;
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.FILE_NOT_FOUND, "File not found 
when retrieving ref file <"+fileString+">: "+e.getMessage(), null);
                        } catch (IOException e) {
-                               // **FIXME** FCPify
-                               System.err.println("Did not parse: "+e);
-                               e.printStackTrace();
-                               return;
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.FILE_PARSE_ERROR, "IO error while 
retrieving ref file <"+fileString+">: "+e.getMessage(), null);
                        }
                        ref = ref.trim();
-                       if(ref == null) return;  // **FIXME** FCPify
-                       if(ref.equals("")) return;  // **FIXME** FCPify
+                       if(ref == null) {
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from file <"+fileString+">", null);
+                       }
+                       if(ref.equals("")) {
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from file <"+fileString+">", null);
+                       }
                        try {
                                fs = new SimpleFieldSet(ref, true);
                        } catch (IOException e) {
-                               // **FIXME** FCPify
-                               System.err.println("Did not parse: "+e);
-                               e.printStackTrace();
-                               return;
+                               throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
ref from file <"+fileString+">: "+e.getMessage(), null);
                        }
                }
                PeerNode pn;
                try {
                        pn = new PeerNode(fs, node, false);
-               } catch (FSParseException e1) {
-                       // **FIXME** FCPify
-                       System.err.println("Did not parse: "+e1);
-                       Logger.error(this, "Did not parse: "+e1, e1);
-                       return;
-               } catch (PeerParseException e1) {
-                       // **FIXME** FCPify
-                       System.err.println("Did not parse: "+e1);
-                       Logger.error(this, "Did not parse: "+e1, e1);
-                       return;
+               } catch (FSParseException e) {
+                       throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
retrieved ref: "+e.getMessage(), null);
+               } catch (PeerParseException e) {
+                       throw new 
MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing 
retrieved ref: "+e.getMessage(), null);
                }
                // **FIXME** Handle duplicates somehow maybe?  What about when 
node.addDarknetConnection() fails for some reason?
                if(node.addDarknetConnection(pn))

Modified: trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java        
2006-07-07 16:39:56 UTC (rev 9492)
+++ trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java        
2006-07-07 17:54:23 UTC (rev 9493)
@@ -38,6 +38,10 @@
        static final int INTERNAL_ERROR = 17;
        static final int SHUTTING_DOWN = 18;
        static final int NO_SUCH_NODE_IDENTIFIER = 19;
+       static final int URL_PARSE_ERROR = 20;
+       static final int REF_PARSE_ERROR = 21;
+       static final int FILE_PARSE_ERROR = 22;
+       static final int NOT_A_FILE_ERROR = 23;

        final int code;
        final String extra;
@@ -84,6 +88,14 @@
                        return "Shutting down";
                case NO_SUCH_NODE_IDENTIFIER:
                        return "No such nodeIdentifier";
+               case URL_PARSE_ERROR:
+                       return "Error parsing URL";
+               case REF_PARSE_ERROR:
+                       return "Reference could not be parsed";
+               case FILE_PARSE_ERROR:
+                       return "File could not be read";
+               case NOT_A_FILE_ERROR:
+                       return "Filepath is not a file";
                default:
                        Logger.error(this, "Unknown error code: "+code, new 
Exception("debug"));
                return "(Unknown)";


Reply via email to