Error Handling
- Errors that occur during initialization no longer prevent the display of debug info.
This commit is contained in:
143
src/Context.cpp
143
src/Context.cpp
@@ -65,85 +65,114 @@ Context::~Context ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Context::initialize (int argc, const char** argv)
|
int Context::initialize (int argc, const char** argv)
|
||||||
{
|
{
|
||||||
Timer t ("Context::initialize");
|
Timer t ("Context::initialize");
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
// char** argv --> std::vector <std::string> Context::args.
|
try
|
||||||
// TODO Handle "cal" case here.
|
{
|
||||||
args.capture (argc, argv);
|
// char** argv --> std::vector <std::string> Context::args.
|
||||||
|
// TODO Handle "cal" case here.
|
||||||
|
args.capture (argc, argv);
|
||||||
|
|
||||||
// echo one two -- three | task zero --> task zero one two
|
// echo one two -- three | task zero --> task zero one two
|
||||||
// 'three' is left in the input buffer.
|
// 'three' is left in the input buffer.
|
||||||
args.append_stdin ();
|
args.append_stdin ();
|
||||||
|
|
||||||
// Assume default .taskrc and .task locations.
|
// Assume default .taskrc and .task locations.
|
||||||
assumeLocations ();
|
assumeLocations ();
|
||||||
|
|
||||||
// Process 'rc:<file>' command line override, and remove the argument from the
|
// Process 'rc:<file>' command line override, and remove the argument from the
|
||||||
// Context::args.
|
// Context::args.
|
||||||
args.rc_override (home_dir, rc_file);
|
args.rc_override (home_dir, rc_file);
|
||||||
|
|
||||||
// Dump any existing values and load rc file.
|
// Dump any existing values and load rc file.
|
||||||
config.clear ();
|
config.clear ();
|
||||||
config.load (rc_file);
|
config.load (rc_file);
|
||||||
|
|
||||||
// The data location, Context::data_dir, is determined from the assumed
|
// The data location, Context::data_dir, is determined from the assumed
|
||||||
// location (~/.task), or set by data.location in the config file, or
|
// location (~/.task), or set by data.location in the config file, or
|
||||||
// overridden by rc.data.location on the command line.
|
// overridden by rc.data.location on the command line.
|
||||||
std::string location;
|
std::string location;
|
||||||
args.get_data_location (location);
|
args.get_data_location (location);
|
||||||
data_dir = Directory (location);
|
data_dir = Directory (location);
|
||||||
extension_dir = data_dir.data + "/extensions";
|
extension_dir = data_dir.data + "/extensions";
|
||||||
|
|
||||||
// Create missing config file and data directory, if necessary.
|
// Create missing config file and data directory, if necessary.
|
||||||
createDefaultConfig ();
|
createDefaultConfig ();
|
||||||
|
|
||||||
// Handle Aliases.
|
// Handle Aliases.
|
||||||
loadAliases ();
|
loadAliases ();
|
||||||
args.resolve_aliases ();
|
args.resolve_aliases ();
|
||||||
|
|
||||||
// Apply rc overrides to Context::config, capturing raw args for later use.
|
// Apply rc overrides to Context::config, capturing raw args for later use.
|
||||||
args.apply_overrides ();
|
args.apply_overrides ();
|
||||||
|
|
||||||
// Initialize the color rules, if necessary.
|
// Initialize the color rules, if necessary.
|
||||||
if (color ())
|
if (color ())
|
||||||
initializeColorRules ();
|
initializeColorRules ();
|
||||||
|
|
||||||
// Instantiate built-in command objects.
|
// Instantiate built-in command objects.
|
||||||
Command::factory (commands);
|
Command::factory (commands);
|
||||||
|
|
||||||
// Instantiate built-in column objects.
|
// Instantiate built-in column objects.
|
||||||
Column::factory (columns);
|
Column::factory (columns);
|
||||||
|
|
||||||
// Categorize all arguments one more time.
|
// Categorize all arguments one more time.
|
||||||
args.categorize ();
|
args.categorize ();
|
||||||
|
|
||||||
// Handle default command and assumed 'info' command.
|
// Handle default command and assumed 'info' command.
|
||||||
args.inject_defaults ();
|
args.inject_defaults ();
|
||||||
|
|
||||||
// TODO Instantiate extension command objects.
|
// TODO Instantiate extension command objects.
|
||||||
// TODO Instantiate default command object.
|
// TODO Instantiate default command object.
|
||||||
|
|
||||||
// TODO Instantiate extension column objects.
|
// TODO Instantiate extension column objects.
|
||||||
|
|
||||||
// TODO Instantiate extension UDA objects.
|
// TODO Instantiate extension UDA objects.
|
||||||
// TODO Instantiate extension format objects.
|
// TODO Instantiate extension format objects.
|
||||||
|
|
||||||
// If there is a locale variant (en-US.<variant>), then strip it.
|
// If there is a locale variant (en-US.<variant>), then strip it.
|
||||||
std::string locale = config.get ("locale");
|
std::string locale = config.get ("locale");
|
||||||
std::string::size_type period = locale.find ('.');
|
std::string::size_type period = locale.find ('.');
|
||||||
if (period != std::string::npos)
|
if (period != std::string::npos)
|
||||||
locale = locale.substr (0, period);
|
locale = locale.substr (0, period);
|
||||||
|
|
||||||
// Initialize the database.
|
// Initialize the database.
|
||||||
tdb.clear ();
|
tdb.clear ();
|
||||||
tdb.location (data_dir);
|
tdb.location (data_dir);
|
||||||
|
|
||||||
// Hook system init, plus post-start event occurring at the first possible
|
// Hook system init, plus post-start event occurring at the first possible
|
||||||
// moment after hook initialization.
|
// moment after hook initialization.
|
||||||
hooks.initialize ();
|
hooks.initialize ();
|
||||||
hooks.trigger ("on-launch");
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
Context (const Context&);
|
Context (const Context&);
|
||||||
Context& operator= (const Context&);
|
Context& operator= (const Context&);
|
||||||
|
|
||||||
void initialize (int, const char**); // all startup
|
int initialize (int, const char**); // all startup
|
||||||
int run ();
|
int run ();
|
||||||
int dispatch (std::string&); // command handler dispatch
|
int dispatch (std::string&); // command handler dispatch
|
||||||
void shadow (); // shadow file update
|
void shadow (); // shadow file update
|
||||||
|
|||||||
@@ -61,8 +61,9 @@ int main (int argc, const char** argv)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
context.initialize (argc, argv);
|
status = context.initialize (argc, argv);
|
||||||
status = context.run ();
|
if (status == 0)
|
||||||
|
status = context.run ();
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (std::string& error)
|
catch (std::string& error)
|
||||||
|
|||||||
Reference in New Issue
Block a user