summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesper K. Pedersen <[email protected]>2013-04-17 14:52:52 +0200
committerJesper K. Pedersen <[email protected]>2013-04-17 20:50:44 +0200
commitcf9aee24f52704f70a5cb59e8cf15258d7e17445 (patch)
treead01aa7a3ca1d3bf25e844b061cd88678b4874a9
parent487770e422e4c55e128c210bb82b30ed99f3f401 (diff)
improved error handling
Change-Id: I3cd3632c17fb542cb0ab32a2ebebfc3c780aae22 Reviewed-by: Nicolas Arnaud-Cormos <[email protected]>
-rw-r--r--scriptmanager.cpp9
-rw-r--r--scriptrunner.cpp9
-rw-r--r--scriptrunner.h11
3 files changed, 21 insertions, 8 deletions
diff --git a/scriptmanager.cpp b/scriptmanager.cpp
index 882839c..00b5b91 100644
--- a/scriptmanager.cpp
+++ b/scriptmanager.cpp
@@ -150,12 +150,13 @@ void ScriptManager::runFile(const QString &fileName)
Core::MessageManager::instance()->showOutputPane();
Core::MessageManager::instance()->printToOutputPane(tr("Start %1...").arg(fileName),
Utils::NormalMessageFormat);
- if(m_runner->runScript(sourceCode, fileName))
+ ErrorMessage message = m_runner->runScript(sourceCode, fileName);
+ if (message.hasError)
+ Core::MessageManager::instance()->printToOutputPane(tr("Error at line %1: %2\n").arg(message.line).arg(message.message),
+ Utils::ErrorMessageFormat);
+ else
Core::MessageManager::instance()->printToOutputPane(tr("The script exited normally\n"),
Utils::NormalMessageFormat);
- else
- Core::MessageManager::instance()->printToOutputPane(tr("The script has unexpectedly finished.\n"),
- Utils::ErrorMessageFormat);
}
else {
Core::MessageManager::instance()->printToOutputPane(tr("Error: %1 doesn't exist.\n").arg(fileName),
diff --git a/scriptrunner.cpp b/scriptrunner.cpp
index a02aaaf..5df00fc 100644
--- a/scriptrunner.cpp
+++ b/scriptrunner.cpp
@@ -59,12 +59,12 @@ ScriptRunner::~ScriptRunner()
}
-bool ScriptRunner::runScript(const QString &sourceCode, const QString fileName)
+ErrorMessage ScriptRunner::runScript(const QString &sourceCode, const QString fileName)
{
ensureEngineInitialized();
m_engine->pushContext();
- m_engine->evaluate(sourceCode, fileName);
+ QScriptValue result = m_engine->evaluate(sourceCode, fileName);
const bool failed = m_engine->hasUncaughtException();
m_engine->popContext();
@@ -74,7 +74,10 @@ bool ScriptRunner::runScript(const QString &sourceCode, const QString fileName)
if (editorManager->currentEditor())
editorManager->currentEditor()->widget()->setFocus(Qt::OtherFocusReason);
- return !failed;
+ if ( failed)
+ return ErrorMessage(m_engine->uncaughtExceptionLineNumber(), result.toString());
+
+ return ErrorMessage();
}
diff --git a/scriptrunner.h b/scriptrunner.h
index 861c478..7cc65d1 100644
--- a/scriptrunner.h
+++ b/scriptrunner.h
@@ -41,6 +41,15 @@
namespace Scripting {
namespace Internal {
+struct ErrorMessage {
+ ErrorMessage() : hasError(false) {}
+ ErrorMessage(int line, const QString& message) : hasError(true), line(line), message(message) {}
+
+ bool hasError;
+ int line;
+ QString message;
+};
+
/**
* \brief Script Runner
*
@@ -57,7 +66,7 @@ public:
virtual ~ScriptRunner();
// Run a script
- bool runScript(const QString &sourceCode, const QString fileName=QString());
+ ErrorMessage runScript(const QString &sourceCode, const QString fileName=QString());
QScriptEnginePtr scriptEngine() { return ensureEngineInitialized(); }