Skip to content

Commit

Permalink
Re #8686. Added error report to ApplicationWindow.
Browse files Browse the repository at this point in the history
This was done by adding a slot for the error signal and turning
it into a log message and exiting.
  • Loading branch information
peterfpeterson committed Jan 9, 2014
1 parent 681a995 commit dc73803
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Expand Up @@ -16353,6 +16353,7 @@ void ApplicationWindow::executeScriptFile(const QString & filename, const Script
code += in.readLine() + "\n";
}
Script *runner = scriptingEnv()->newScript(filename, this, Script::NonInteractive);
connect(runner, SIGNAL(error(const QString &, const QString &, int)), this, SLOT(onScriptExecuteError(const QString &, const QString &, int)));
runner->redirectStdOut(false);
scriptingEnv()->redirectStdOut(false);
if(execMode == Script::Asynchronous)
Expand All @@ -16373,6 +16374,24 @@ void ApplicationWindow::executeScriptFile(const QString & filename, const Script
delete runner;
}

/**
* This is the slot for handing script execution errors. It is only
* attached by ::executeScriptFile which is only done in the '-xq'
* command line option.
*
* @param message Normally the stacktrace of the error.
* @param scriptName The name of the file.
* @param lineNumber The line number in the script that caused the error.
*/
void ApplicationWindow::onScriptExecuteError(const QString & message, const QString & scriptName, int lineNumber)
{
g_log.fatal() << "Fatal error on line " << lineNumber << " of \"" << scriptName.toStdString()
<< "\" encountered:\n"
<< message.toStdString();
this->setExitCode(1);
this->exitWithPresetCode();
}

/**
* Run Python code
* @param code :: An arbitrary string of python code
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.h
Expand Up @@ -238,6 +238,8 @@ public slots:
ApplicationWindow * loadScript(const QString& fn);
/// Runs a script from a file. Mainly useful for automatically running scripts
void executeScriptFile(const QString & filename, const Script::ExecutionMode execMode);
/// Slot to connect the script execution errors to
void onScriptExecuteError(const QString & message, const QString & scriptName, int lineNumber);
/// Runs an arbitrary lump of python code, return true/false on success/failure.
bool runPythonScript(const QString & code, bool async = false, bool quiet=false, bool redirect=true);

Expand Down

0 comments on commit dc73803

Please sign in to comment.