error message associated with an alignment file loading failure is passed back to...
[jalview.git] / src / jalview / io / FileParse.java
index eb10375..8a97e39 100755 (executable)
@@ -37,6 +37,7 @@ public class FileParse
   protected BufferedReader dataIn=null;
   protected String errormessage="UNITIALISED SOURCE";
   protected boolean error=true;
+  protected String warningMessage=null;
   /**
    * size of readahead buffer used for when initial stream position is marked.
    */
@@ -127,6 +128,7 @@ public class FileParse
     else if (type.equals(AppletFormatAdapter.URL))
     {
       try {
+      try {
         checkURLSource(fileStr);
         if (suffixSeparator=='#')
           extractSuffix(fileStr); // URL lref is stored for later reference.
@@ -145,6 +147,12 @@ public class FileParse
           }
         }
       }
+      }
+      catch (Exception e)
+      {
+        errormessage = "CANNOT ACCESS DATA AT URL '"+fileStr+"' ("+e.getMessage()+")";
+        error=true;
+      }
     }
     else if (type.equals(AppletFormatAdapter.PASTE))
     {
@@ -167,6 +175,11 @@ public class FileParse
         error = true;
       }
     }
+    if (dataIn==null)
+    {
+      // pass up the reason why we have no source to read from
+      throw new IOException("Failed to read data from source:\n"+errormessage);
+    }
     error=false;
     dataIn.mark(READAHEAD_LIMIT);
   }
@@ -206,4 +219,18 @@ public class FileParse
       throw new IOException("Implementation Error: Reset called for invalid source.");
     }
   }
+  /**
+   * 
+   * @return true if there is a warning for the user
+   */
+  public boolean hasWarningMessage() {
+    return (warningMessage!=null && warningMessage.length()>0);
+  }
+  /**
+   * 
+   * @return empty string or warning message about file that was just parsed.
+   */
+  public String getWarningMessage() {
+    return warningMessage;
+  }
 }