History

Add exception information to script status

Ryan Huffman committed 9 years ago

Commit 888d7ab1 parent 4e358f71 file · +8 −6Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+8−6
@@ -147,19 +147,19 @@ static bool hasCorrectSyntax(const QScriptProgram& program, ScriptEngine* report · 146 unmodified lines
147 return true;147 return true;
148}148}
149 149
150static bool hadUncaughtExceptions(QScriptEngine& engine, const QString& fileName, ScriptEngine* reportingEngine) {150static bool hadUncaughtExceptions(QScriptEngine& engine, const QString& fileName, ScriptEngine* reportingEngine, QString& exceptionMessage = QString()) {
151 if (engine.hasUncaughtException()) {151 if (engine.hasUncaughtException()) {
152 const auto backtrace = engine.uncaughtExceptionBacktrace();152 const auto backtrace = engine.uncaughtExceptionBacktrace();
153 const auto exception = engine.uncaughtException().toString();153 const auto exception = engine.uncaughtException().toString();
154 const auto line = QString::number(engine.uncaughtExceptionLineNumber());154 const auto line = QString::number(engine.uncaughtExceptionLineNumber());
155 engine.clearExceptions();155 engine.clearExceptions();
156 156
157 auto message = QString(SCRIPT_EXCEPTION_FORMAT).arg(exception, fileName, line);157 exceptionMessage = QString(SCRIPT_EXCEPTION_FORMAT).arg(exception, fileName, line);
158 if (!backtrace.empty()) {158 if (!backtrace.empty()) {
159 static const auto lineSeparator = "\n ";159 static const auto lineSeparator = "\n ";
160 message += QString("\n[Backtrace]%1%2").arg(lineSeparator, backtrace.join(lineSeparator));160 exceptionMessage += QString("\n[Backtrace]%1%2").arg(lineSeparator, backtrace.join(lineSeparator));
161 }161 }
162 reportingEngine->scriptErrorMessage(qPrintable(message));162 reportingEngine->scriptErrorMessage(qPrintable(exceptionMessage));
163 return true;163 return true;
164 }164 }
165 return false;165 return false;
@@ -1472,9 +1472,11 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 1306 unmodified lines
1472 });1472 });
1473 testConstructor = sandbox.evaluate(program);1473 testConstructor = sandbox.evaluate(program);
1474 }1474 }
1475 if (hadUncaughtExceptions(sandbox, program.fileName(), this)) {1475
1476 QString exceptionMessage;
1477 if (hadUncaughtExceptions(sandbox, program.fileName(), this, exceptionMessage)) {
1476 newDetails.status = ERROR_RUNNING_SCRIPT;1478 newDetails.status = ERROR_RUNNING_SCRIPT;
1477 newDetails.errorInfo = "Exception";1479 newDetails.errorInfo = exceptionMessage;
1478 _entityScripts[entityID] = newDetails;1480 _entityScripts[entityID] = newDetails;
1479 1481
1480 return;1482 return;