mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Error Handling
- Errors that occur during initialization no longer prevent the display of debug info.
This commit is contained in:
parent
5e693b2530
commit
01253f1cdf
3 changed files with 90 additions and 60 deletions
|
@ -65,10 +65,13 @@ Context::~Context ()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Context::initialize (int argc, const char** argv)
|
||||
int Context::initialize (int argc, const char** argv)
|
||||
{
|
||||
Timer t ("Context::initialize");
|
||||
int rc = 0;
|
||||
|
||||
try
|
||||
{
|
||||
// char** argv --> std::vector <std::string> Context::args.
|
||||
// TODO Handle "cal" case here.
|
||||
args.capture (argc, argv);
|
||||
|
@ -146,6 +149,32 @@ void Context::initialize (int argc, const char** argv)
|
|||
hooks.trigger ("on-launch");
|
||||
}
|
||||
|
||||
catch (const std::string& error)
|
||||
{
|
||||
footnote (error);
|
||||
rc = 2;
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
footnote (STRING_UNKNOWN_ERROR);
|
||||
rc = 3;
|
||||
}
|
||||
|
||||
// Dump all debug messages, controlled by rc.debug.
|
||||
if (rc && config.getBoolean ("debug"))
|
||||
{
|
||||
std::vector <std::string>::iterator d;
|
||||
for (d = debugMessages.begin (); d != debugMessages.end (); ++d)
|
||||
if (color ())
|
||||
std::cout << colorizeDebug (*d) << "\n";
|
||||
else
|
||||
std::cout << *d << "\n";
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Context::run ()
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
Context (const Context&);
|
||||
Context& operator= (const Context&);
|
||||
|
||||
void initialize (int, const char**); // all startup
|
||||
int initialize (int, const char**); // all startup
|
||||
int run ();
|
||||
int dispatch (std::string&); // command handler dispatch
|
||||
void shadow (); // shadow file update
|
||||
|
|
|
@ -61,7 +61,8 @@ int main (int argc, const char** argv)
|
|||
|
||||
try
|
||||
{
|
||||
context.initialize (argc, argv);
|
||||
status = context.initialize (argc, argv);
|
||||
if (status == 0)
|
||||
status = context.run ();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue