more error messages for loading an annotation.
authorDiane Trout <diane@caltech.edu>
Tue, 20 Feb 2007 23:26:37 +0000 (23:26 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 20 Feb 2007 23:26:37 +0000 (23:26 +0000)
ticket:239
Return specific error messages if a path doesn't exist or is a directory
instead of a more generic there was a problem loading.

alg/sequence.cpp
alg/test/test_mussa.cpp

index 147fdce3b7e2c015eb20741964327954f70a924a..452f5f98f204d37bf0f85f173eb1f42fc2a07313 100644 (file)
@@ -22,6 +22,7 @@
 //                           ---------- sequence.cc -----------
 //                        ----------------------------------------
 #include <boost/filesystem/fstream.hpp>
+#include <boost/filesystem/operations.hpp>
 namespace fs = boost::filesystem;
 
 #include <boost/spirit/core.hpp>
@@ -313,10 +314,18 @@ void Sequence::set_filtered_sequence(const std::string &in_seq,
 void
 Sequence::load_annot(fs::path file_path, int start_index, int end_index)
 {
+  if (not fs::exists(file_path)) {
+    throw mussa_load_error("Annotation File " + file_path.string() + " was not found");
+  }
+  if (fs::is_directory(file_path)) {
+    throw mussa_load_error(file_path.string() +
+            " is a directory, please provide a file for annotations."
+          );
+  }    
   fs::fstream data_stream(file_path, std::ios::in);
   if (!data_stream)
   {
-    throw mussa_load_error("Sequence File: " + file_path.string() + " not found");
+    throw mussa_load_error("Error loading annotation file " + file_path.string());
   }
 
   // so i should probably be passing the parse function some iterators
index 4d966272ccb6592b30f1011410b9c458c1650184..16068473c01500185aedec71871fd90cd1818374 100644 (file)
@@ -161,6 +161,14 @@ BOOST_AUTO_TEST_CASE( mussa_mupa_is_file_not_directory )
   BOOST_CHECK_THROW(m1.load_mupa_file( curdir ), mussa_load_error );
 }
 
+// catch error if annotation isn't a file
+BOOST_AUTO_TEST_CASE( mussa_annotation_is_not_file )
+{
+  Mussa m1;
+  fs::path full_path(fs::path(EXAMPLE_DIR, fs::native) / "directory.mupa");
+  BOOST_CHECK_THROW( m1.load_mupa_file( full_path ), mussa_load_error );
+}
+
 BOOST_AUTO_TEST_CASE( mussa_load_analysis )
 {
   fs::path example_dir(EXAMPLE_DIR, fs::native);