Diagnostics - Better parsing errors

- Improved the errors when parsing a corrupt or unrecognized pending.data
  or completed.data file.
This commit is contained in:
Paul Beckingham 2009-05-03 00:18:23 -04:00
parent 3235ac592f
commit a0838474c4
2 changed files with 77 additions and 15 deletions

View file

@ -575,6 +575,9 @@ void T::parse (const std::string& line)
openAttrBracket + 1, closeAttrBracket - openAttrBracket - 1); openAttrBracket + 1, closeAttrBracket - openAttrBracket - 1);
std::vector <std::string> pairs; std::vector <std::string> pairs;
split (pairs, attributes, ' '); split (pairs, attributes, ' ');
if (pairs.size () == 0)
throw std::string ("Could not find any attributes.");
for (size_t i = 0; i < pairs.size (); ++i) for (size_t i = 0; i < pairs.size (); ++i)
{ {
std::vector <std::string> pair; std::vector <std::string> pair;
@ -623,15 +626,17 @@ void T::parse (const std::string& line)
mDescription = line.substr (closeAnnoBracket + 2, std::string::npos); mDescription = line.substr (closeAnnoBracket + 2, std::string::npos);
} }
else
throw std::string ("Missing annotation brackets.");
} }
else else
throw std::string ("Missing attribute brackets"); throw std::string ("Missing attribute brackets.");
} }
else else
throw std::string ("Missing tag brackets"); throw std::string ("Missing tag brackets.");
} }
else else
throw std::string ("Line too short"); throw std::string ("Line too short.");
} }
break; break;

View file

@ -26,6 +26,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream>
#include <sys/file.h> #include <sys/file.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
@ -104,13 +105,27 @@ bool TDB::pendingT (std::vector <T>& all)
{ {
mId = 1; mId = 1;
int line = 1;
std::vector <std::string>::iterator it; std::vector <std::string>::iterator it;
for (it = lines.begin (); it != lines.end (); ++it) for (it = lines.begin (); it != lines.end (); ++it)
{ {
T t (*it); try
t.setId (mId++); {
if (t.getStatus () == T::pending) T t (*it);
all.push_back (t); 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; return true;
@ -130,12 +145,26 @@ bool TDB::allPendingT (std::vector <T>& all)
{ {
mId = 1; mId = 1;
int line = 1;
std::vector <std::string>::iterator it; std::vector <std::string>::iterator it;
for (it = lines.begin (); it != lines.end (); ++it) for (it = lines.begin (); it != lines.end (); ++it)
{ {
T t (*it); try
t.setId (mId++); {
all.push_back (t); 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; return true;
@ -152,12 +181,26 @@ bool TDB::completedT (std::vector <T>& all) const
std::vector <std::string> lines; std::vector <std::string> lines;
if (readLockedFile (mCompletedFile, lines)) if (readLockedFile (mCompletedFile, lines))
{ {
int line = 1;
std::vector <std::string>::iterator it; std::vector <std::string>::iterator it;
for (it = lines.begin (); it != lines.end (); ++it) for (it = lines.begin (); it != lines.end (); ++it)
{ {
T t (*it); try
if (t.getStatus () != T::deleted) {
all.push_back (t); 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; return true;
@ -174,11 +217,25 @@ bool TDB::allCompletedT (std::vector <T>& all) const
std::vector <std::string> lines; std::vector <std::string> lines;
if (readLockedFile (mCompletedFile, lines)) if (readLockedFile (mCompletedFile, lines))
{ {
int line = 1;
std::vector <std::string>::iterator it; std::vector <std::string>::iterator it;
for (it = lines.begin (); it != lines.end (); ++it) for (it = lines.begin (); it != lines.end (); ++it)
{ {
T t (*it); try
all.push_back (t); {
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; return true;