diff options
| author | Jesper K. Pedersen <jesper.pedersen@kdab.com> | 2013-04-25 17:26:14 +0200 |
|---|---|---|
| committer | Jesper K. Pedersen <jesper.pedersen@kdab.com> | 2013-04-30 06:53:33 +0200 |
| commit | fee8bd788e7ee8c2c90fd2ebc49c22e7a1b6672d (patch) | |
| tree | 2088d649b4448406d12919bfd75f84d0e028fe38 /scriptrunner.cpp | |
| parent | 74ac0a518fcb79f14ab655ce68d424c034f6b846 (diff) | |
improve error handling
Change-Id: Id134d873cb1171c9f8b5cad90254828d93776cbd
Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
Diffstat (limited to 'scriptrunner.cpp')
| -rw-r--r-- | scriptrunner.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/scriptrunner.cpp b/scriptrunner.cpp index 411da03..0d99d42 100644 --- a/scriptrunner.cpp +++ b/scriptrunner.cpp @@ -69,6 +69,10 @@ ScriptRunner::~ScriptRunner() // Path to the topmost script loaded. static QString currentPath; +// The backtrace does unfortunately not include the file in which an error occurred, +// we therefore need this variable to store this information. +static QString errorFileName; + static QScriptValue run(QScriptEngine* engine, const QString& fileName, bool recursive) { QFile file(fileName); @@ -88,6 +92,8 @@ static QScriptValue run(QScriptEngine* engine, const QString& fileName, bool rec } QScriptValue result = engine->evaluate(sourceCode, fileName); + if (engine->hasUncaughtException() && errorFileName.isNull() ) + errorFileName = fileName; return result; } @@ -111,6 +117,7 @@ static QScriptValue load(QScriptContext *context, QScriptEngine *engine) ErrorMessage ScriptRunner::runScript(const QString fileName) { + errorFileName = QString(); currentPath = QFileInfo(fileName).absolutePath(); ensureEngineInitialized(); @@ -125,8 +132,8 @@ ErrorMessage ScriptRunner::runScript(const QString fileName) if (editorManager->currentEditor()) editorManager->currentEditor()->widget()->setFocus(Qt::OtherFocusReason); - if ( failed) - return ErrorMessage(m_engine->uncaughtExceptionLineNumber(), result.toString()); + if (failed) + return ErrorMessage(errorFileName, m_engine->uncaughtExceptionLineNumber(), result.toString()); return ErrorMessage(); } |
