Improve location information for exceptions

fixes #10568
This commit is contained in:
Gunnar Beutner 2015-11-10 17:04:49 +01:00
parent 7c361853ad
commit 2d2e7ecdb2
5 changed files with 16 additions and 17 deletions

View File

@ -57,11 +57,13 @@ DebugInfo icinga::DebugInfoRange(const DebugInfo& start, const DebugInfo& end)
#define EXTRA_LINES 2
void icinga::ShowCodeFragment(std::ostream& out, const DebugInfo& di, bool verbose)
void icinga::ShowCodeLocation(std::ostream& out, const DebugInfo& di, bool verbose)
{
if (di.Path.IsEmpty())
return;
out << "Location: " << di << "\n";
std::ifstream ifs;
ifs.open(di.Path.CStr(), std::ifstream::in);

View File

@ -48,7 +48,7 @@ I2_BASE_API std::ostream& operator<<(std::ostream& out, const DebugInfo& val);
I2_BASE_API DebugInfo DebugInfoRange(const DebugInfo& start, const DebugInfo& end);
I2_BASE_API void ShowCodeFragment(std::ostream& out, const DebugInfo& di, bool verbose = true);
I2_BASE_API void ShowCodeLocation(std::ostream& out, const DebugInfo& di, bool verbose = true);
}

View File

@ -140,16 +140,14 @@ String icinga::DiagnosticInformation(const std::exception& ex, bool verbose, Sta
const ValidationError *vex = dynamic_cast<const ValidationError *>(&ex);
if (message.IsEmpty())
result << boost::diagnostic_information(ex);
result << boost::diagnostic_information(ex) << "\n";
else
result << "Error: " << message;
result << "Error: " << message << "\n";
const ScriptError *dex = dynamic_cast<const ScriptError *>(&ex);
if (dex && !dex->GetDebugInfo().Path.IsEmpty()) {
result << "\nLocation:\n";
ShowCodeFragment(result, dex->GetDebugInfo());
}
if (dex && !dex->GetDebugInfo().Path.IsEmpty())
ShowCodeLocation(result, dex->GetDebugInfo());
if (vex) {
DebugInfo di;
@ -187,10 +185,8 @@ String icinga::DiagnosticInformation(const std::exception& ex, bool verbose, Sta
di.LastColumn = message->Get(5);
}
if (!di.Path.IsEmpty()) {
result << "\nLocation:\n";
ShowCodeFragment(result, di);
}
if (!di.Path.IsEmpty())
ShowCodeLocation(result, di);
}
const user_error *uex = dynamic_cast<const user_error *>(&ex);

View File

@ -59,12 +59,13 @@ void ConsoleCommand::BreakpointHandler(ScriptFrame& frame, ScriptError *ex, cons
if (ex && ex->IsHandledByDebugger())
return;
std::cout << "Breakpoint encountered " << di << "\n";
std::cout << "Breakpoint encountered.\n";
if (ex) {
std::cout << "Exception: " << DiagnosticInformation(*ex);
std::cout << "Exception: " << DiagnosticInformation(*ex) << "\n";
ex->SetHandledByDebugger(true);
}
} else
ShowCodeLocation(std::cout, di);
std::cout << "You can inspect expressions (such as variables) by entering them at the prompt.\n"
<< "To leave the debugger and continue the program use \"$continue\".\n";
@ -358,7 +359,7 @@ incomplete:
}
}
} else {
ShowCodeFragment(std::cout, di);
ShowCodeLocation(std::cout, di);
}
std::cout << ex.what() << "\n";

View File

@ -56,7 +56,7 @@ ExpressionResult Expression::Evaluate(ScriptFrame& frame, DebugHint *dhint) cons
try {
#ifdef I2_DEBUG
/* std::ostringstream msgbuf;
ShowCodeFragment(msgbuf, GetDebugInfo(), false);
ShowCodeLocation(msgbuf, GetDebugInfo(), false);
Log(LogDebug, "Expression")
<< "Executing:\n" << msgbuf.str();*/
#endif /* I2_DEBUG */