mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-25 21:27:19 +02:00
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:
parent
4e63d93005
commit
1a4469d388
3 changed files with 61 additions and 3 deletions
|
@ -2246,10 +2246,12 @@ std::string handleCustomReport (
|
|||
std::string columnList = conf.get ("report." + report + ".columns");
|
||||
std::vector <std::string> columns;
|
||||
split (columns, columnList, ',');
|
||||
validReportColumns (columns);
|
||||
|
||||
std::string sortList = conf.get ("report." + report + ".sort");
|
||||
std::vector <std::string> sortOrder;
|
||||
split (sortOrder, sortList, ',');
|
||||
validSortColumns (columns, sortOrder);
|
||||
|
||||
std::string filterList = conf.get ("report." + report + ".filter");
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -103,6 +103,8 @@ std::string handleReportOldest (TDB&, T&, Config&);
|
|||
std::string handleReportNewest (TDB&, T&, Config&);
|
||||
|
||||
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
|
||||
bool confirm (const std::string&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue