From a0838474c4dcbf57021bc1dd1fbe89c6eac4ebda Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 3 May 2009 00:18:23 -0400 Subject: [PATCH] Diagnostics - Better parsing errors - Improved the errors when parsing a corrupt or unrecognized pending.data or completed.data file. --- src/T.cpp | 11 ++++++-- src/TDB.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 77 insertions(+), 15 deletions(-) diff --git a/src/T.cpp b/src/T.cpp index 43495f542..842613c56 100644 --- a/src/T.cpp +++ b/src/T.cpp @@ -575,6 +575,9 @@ void T::parse (const std::string& line) openAttrBracket + 1, closeAttrBracket - openAttrBracket - 1); std::vector pairs; split (pairs, attributes, ' '); + if (pairs.size () == 0) + throw std::string ("Could not find any attributes."); + for (size_t i = 0; i < pairs.size (); ++i) { std::vector pair; @@ -623,15 +626,17 @@ void T::parse (const std::string& line) mDescription = line.substr (closeAnnoBracket + 2, std::string::npos); } + else + throw std::string ("Missing annotation brackets."); } else - throw std::string ("Missing attribute brackets"); + throw std::string ("Missing attribute brackets."); } else - throw std::string ("Missing tag brackets"); + throw std::string ("Missing tag brackets."); } else - throw std::string ("Line too short"); + throw std::string ("Line too short."); } break; diff --git a/src/TDB.cpp b/src/TDB.cpp index 0ab4ed10a..bf565fa33 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -26,6 +26,7 @@ //////////////////////////////////////////////////////////////////////////////// #include #include +#include #include #include #include @@ -104,13 +105,27 @@ bool TDB::pendingT (std::vector & all) { mId = 1; + int line = 1; std::vector ::iterator it; for (it = lines.begin (); it != lines.end (); ++it) { - T t (*it); - t.setId (mId++); - if (t.getStatus () == T::pending) - all.push_back (t); + try + { + T t (*it); + t.setId (mId++); + if (t.getStatus () == T::pending) + all.push_back (t); + } + + catch (std::string& e) + { + std::stringstream more; + more << " Line " << line << ", in " << "pending.data"; + + throw e + more.str (); + } + + ++line; } return true; @@ -130,12 +145,26 @@ bool TDB::allPendingT (std::vector & all) { mId = 1; + int line = 1; std::vector ::iterator it; for (it = lines.begin (); it != lines.end (); ++it) { - T t (*it); - t.setId (mId++); - all.push_back (t); + try + { + T t (*it); + t.setId (mId++); + all.push_back (t); + } + + catch (std::string& e) + { + std::stringstream more; + more << " Line " << line << ", in " << "pending.data"; + + throw e + more.str (); + } + + ++line; } return true; @@ -152,12 +181,26 @@ bool TDB::completedT (std::vector & all) const std::vector lines; if (readLockedFile (mCompletedFile, lines)) { + int line = 1; std::vector ::iterator it; for (it = lines.begin (); it != lines.end (); ++it) { - T t (*it); - if (t.getStatus () != T::deleted) - all.push_back (t); + try + { + T t (*it); + if (t.getStatus () != T::deleted) + all.push_back (t); + } + + catch (std::string& e) + { + std::stringstream more; + more << " Line " << line << ", in " << "pending.data"; + + throw e + more.str (); + } + + ++line; } return true; @@ -174,11 +217,25 @@ bool TDB::allCompletedT (std::vector & all) const std::vector lines; if (readLockedFile (mCompletedFile, lines)) { + int line = 1; std::vector ::iterator it; for (it = lines.begin (); it != lines.end (); ++it) { - T t (*it); - all.push_back (t); + try + { + T t (*it); + all.push_back (t); + } + + catch (std::string& e) + { + std::stringstream more; + more << " Line " << line << ", in " << "pending.data"; + + throw e + more.str (); + } + + ++line; } return true;