Error handling

- Validates specified columns in custom reports against list of good
  column names.
- Validates list of sort columns in custom reports against list of
  specified column names.
- Minor fix to grammar file.
This commit is contained in:
Paul Beckingham 2009-02-15 22:33:18 -05:00
parent 4e63d93005
commit 1a4469d388
3 changed files with 61 additions and 3 deletions

View file

@ -8,7 +8,7 @@ command ::= simple_command
| id_command | id_command
| "export" file | "export" file
| <id> | <id>
| <id> <substitution> | <id> <substitution> ;
simple_command ::= "version" | "help" | "projects" | "tags" | "next" | "stats" simple_command ::= "version" | "help" | "projects" | "tags" | "next" | "stats"
| "color" ; | "color" ;
@ -27,8 +27,8 @@ filter_part ::= tag_add | tag_remove | attribute | word ;
tag_add ::= "+" word ; tag_add ::= "+" word ;
tag_remove ::= "-" word ; tag_remove ::= "-" word ;
attribute ::= word ":" word ; attribute ::= word ":" word ;
word ::= ... word ::=
file ::= ... file ::=
id ::= digit+ ; id ::= digit+ ;
digit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; digit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
substitution ::= "/" word+ "/" word* "/" ; substitution ::= "/" word+ "/" word* "/" ;

View file

@ -2246,10 +2246,12 @@ std::string handleCustomReport (
std::string columnList = conf.get ("report." + report + ".columns"); std::string columnList = conf.get ("report." + report + ".columns");
std::vector <std::string> columns; std::vector <std::string> columns;
split (columns, columnList, ','); split (columns, columnList, ',');
validReportColumns (columns);
std::string sortList = conf.get ("report." + report + ".sort"); std::string sortList = conf.get ("report." + report + ".sort");
std::vector <std::string> sortOrder; std::vector <std::string> sortOrder;
split (sortOrder, sortList, ','); split (sortOrder, sortList, ',');
validSortColumns (columns, sortOrder);
std::string filterList = conf.get ("report." + report + ".filter"); std::string filterList = conf.get ("report." + report + ".filter");
std::vector <std::string> filterArgs; std::vector <std::string> filterArgs;
@ -2545,3 +2547,57 @@ std::string handleCustomReport (
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void validReportColumns (const std::vector <std::string>& columns)
{
std::vector <std::string> bad;
std::vector <std::string>::const_iterator it;
for (it = columns.begin (); it != columns.end (); ++it)
if (*it != "id" &&
*it != "uuid" &&
*it != "project" &&
*it != "priority" &&
*it != "entry" &&
*it != "start" &&
*it != "due" &&
*it != "age" &&
*it != "active" &&
*it != "tags" &&
*it != "description")
bad.push_back (*it);
if (bad.size ())
{
std::string error;
join (error, ", ", bad);
throw std::string ("Unrecognized column name: ") + error;
}
}
////////////////////////////////////////////////////////////////////////////////
void validSortColumns (
const std::vector <std::string>& columns,
const std::vector <std::string>& sortColumns)
{
std::vector <std::string> bad;
std::vector <std::string>::const_iterator sc;
for (sc = sortColumns.begin (); sc != sortColumns.end (); ++sc)
{
std::vector <std::string>::const_iterator co;
for (co = columns.begin (); co != columns.end (); ++co)
if (sc->substr (0, sc->length () - 1) == *co)
break;
if (co == columns.end ())
bad.push_back (*sc);
}
if (bad.size ())
{
std::string error;
join (error, ", ", bad);
throw std::string ("Sort column is not part of the report: ") + error;
}
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -103,6 +103,8 @@ std::string handleReportOldest (TDB&, T&, Config&);
std::string handleReportNewest (TDB&, T&, Config&); std::string handleReportNewest (TDB&, T&, Config&);
std::string handleCustomReport (TDB&, T&, Config&, const std::string&); std::string handleCustomReport (TDB&, T&, Config&, const std::string&);
void validReportColumns (const std::vector <std::string>&);
void validSortColumns (const std::vector <std::string>&, const std::vector <std::string>&);
// util.cpp // util.cpp
bool confirm (const std::string&); bool confirm (const std::string&);