summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@theqtcompany.com>2015-07-15 17:27:25 +0200
committerChristian Kandeler <christian.kandeler@theqtcompany.com>2015-07-20 11:54:51 +0000
commit96dbcb09924239e7f7dc6547e29cb28003bbe5be (patch)
treeacc7a2b9df19e10385a62ec95e39140f792b9e9b
parent9d025655d5524433ac8ffbbac0f5ab7aa196d797 (diff)
downloadqbs-96dbcb09924239e7f7dc6547e29cb28003bbe5be.tar.gz
Always show the correct error string from the script engine.
Meaning that we check whether the value is an error or the engine has an uncaught exception, and print the respective string. Change-Id: Ie2912e28a82906c7ee9323e2f0e55c6b3de96872 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
-rw-r--r--src/lib/corelib/buildgraph/depscanner.cpp2
-rw-r--r--src/lib/corelib/buildgraph/processcommandexecutor.cpp2
-rw-r--r--src/lib/corelib/buildgraph/rulesapplicator.cpp5
-rw-r--r--src/lib/corelib/buildgraph/transformer.cpp2
-rw-r--r--src/lib/corelib/language/evaluatorscriptclass.cpp2
-rw-r--r--src/lib/corelib/language/language.cpp3
-rw-r--r--src/lib/corelib/language/moduleloader.cpp2
-rw-r--r--src/lib/corelib/language/projectresolver.cpp6
-rw-r--r--src/lib/corelib/language/scriptengine.h4
-rw-r--r--src/lib/corelib/language/tst_language.cpp2
10 files changed, 19 insertions, 11 deletions
diff --git a/src/lib/corelib/buildgraph/depscanner.cpp b/src/lib/corelib/buildgraph/depscanner.cpp
index 503355db1..7bc996a87 100644
--- a/src/lib/corelib/buildgraph/depscanner.cpp
+++ b/src/lib/corelib/buildgraph/depscanner.cpp
@@ -194,7 +194,7 @@ QStringList UserDependencyScanner::evaluate(Artifact *artifact, const ScriptFunc
ctx->popScope();
m_engine->clearRequestedProperties();
if (Q_UNLIKELY(m_engine->hasErrorOrException(result))) {
- QString msg = Tr::tr("evaluating scan script: ") + m_engine->uncaughtException().toString();
+ QString msg = Tr::tr("evaluating scan script: ") + m_engine->lastErrorString(result);
m_engine->clearExceptions();
throw ErrorInfo(msg, script->location);
}
diff --git a/src/lib/corelib/buildgraph/processcommandexecutor.cpp b/src/lib/corelib/buildgraph/processcommandexecutor.cpp
index b40e83649..87ac1c920 100644
--- a/src/lib/corelib/buildgraph/processcommandexecutor.cpp
+++ b/src/lib/corelib/buildgraph/processcommandexecutor.cpp
@@ -188,7 +188,7 @@ QString ProcessCommandExecutor::filterProcessOutput(const QByteArray &_output,
QScriptValue filteredOutput = filterFunction.call(scriptEngine()->undefinedValue(), outputArg);
if (scriptEngine()->hasErrorOrException(filteredOutput)) {
logger().printWarning(ErrorInfo(Tr::tr("Error when calling output filter function: %1")
- .arg(filteredOutput.toString())));
+ .arg(scriptEngine()->lastErrorString(filteredOutput))));
return output;
}
diff --git a/src/lib/corelib/buildgraph/rulesapplicator.cpp b/src/lib/corelib/buildgraph/rulesapplicator.cpp
index 34a53c9ca..529a763a6 100644
--- a/src/lib/corelib/buildgraph/rulesapplicator.cpp
+++ b/src/lib/corelib/buildgraph/rulesapplicator.cpp
@@ -230,7 +230,7 @@ void RulesApplicator::doApply(const ArtifactSet &inputArtifacts, QScriptValue &p
if (Q_UNLIKELY(engine()->hasErrorOrException(scriptValue))) {
QString msg = QLatin1String("evaluating rule binding '%1': %2");
throw ErrorInfo(msg.arg(binding.name.join(QLatin1Char('.')),
- scriptValue.toString()), binding.location);
+ engine()->lastErrorString(scriptValue)), binding.location);
}
setConfigProperty(artifactModulesCfg, binding.name, scriptValue.toVariant());
}
@@ -269,7 +269,8 @@ Artifact *RulesApplicator::createOutputArtifactFromRuleArtifact(
QScriptValue scriptValue = engine()->evaluate(ruleArtifact->filePath);
if (Q_UNLIKELY(engine()->hasErrorOrException(scriptValue))) {
throw ErrorInfo(Tr::tr("Error in Rule.Artifact fileName at %1: %2")
- .arg(ruleArtifact->location.toString(), scriptValue.toString()));
+ .arg(ruleArtifact->location.toString(),
+ engine()->lastErrorString(scriptValue)));
}
QString outputPath = FileInfo::resolvePath(m_product->buildDirectory(), scriptValue.toString());
if (Q_UNLIKELY(outputFilePaths->contains(outputPath))) {
diff --git a/src/lib/corelib/buildgraph/transformer.cpp b/src/lib/corelib/buildgraph/transformer.cpp
index 5d23119f6..c487ce5a2 100644
--- a/src/lib/corelib/buildgraph/transformer.cpp
+++ b/src/lib/corelib/buildgraph/transformer.cpp
@@ -218,7 +218,7 @@ void Transformer::createCommands(const ScriptFunctionConstPtr &script,
engine->clearRequestedProperties();
if (Q_UNLIKELY(engine->hasErrorOrException(scriptValue)))
throw ErrorInfo(Tr::tr("evaluating prepare script: ")
- + engine->uncaughtException().toString(),
+ + engine->lastErrorString(scriptValue),
CodeLocation(script->location.filePath(),
script->location.line() + engine->uncaughtExceptionLineNumber() - 1));
diff --git a/src/lib/corelib/language/evaluatorscriptclass.cpp b/src/lib/corelib/language/evaluatorscriptclass.cpp
index f627038ef..06aa9a3f8 100644
--- a/src/lib/corelib/language/evaluatorscriptclass.cpp
+++ b/src/lib/corelib/language/evaluatorscriptclass.cpp
@@ -182,7 +182,7 @@ private:
engine->currentContext()->popScope();
popScopes();
if (engine->hasErrorOrException(cr)) {
- *result = cr;
+ *result = engine->lastErrorValue(cr);
return;
}
if (cr.toBool()) {
diff --git a/src/lib/corelib/language/language.cpp b/src/lib/corelib/language/language.cpp
index c3959ee34..9668ae60a 100644
--- a/src/lib/corelib/language/language.cpp
+++ b/src/lib/corelib/language/language.cpp
@@ -689,7 +689,8 @@ static QProcessEnvironment getProcessEnvironment(ScriptEngine *engine, EnvType e
QString envTypeStr = (envType == BuildEnv
? QLatin1String("build") : QLatin1String("run"));
throw ErrorInfo(Tr::tr("Error while setting up %1 environment: %2")
- .arg(envTypeStr, scriptValue.toString()), setupScript->location);
+ .arg(envTypeStr, engine->lastErrorString(scriptValue)),
+ setupScript->location);
}
}
diff --git a/src/lib/corelib/language/moduleloader.cpp b/src/lib/corelib/language/moduleloader.cpp
index 723916cd1..77340d179 100644
--- a/src/lib/corelib/language/moduleloader.cpp
+++ b/src/lib/corelib/language/moduleloader.cpp
@@ -1407,7 +1407,7 @@ void ModuleLoader::resolveProbe(Item *parent, Item *probe)
scope.setProperty(b.first, b.second);
QScriptValue sv = m_engine->evaluate(configureScript->sourceCodeForEvaluation());
if (Q_UNLIKELY(m_engine->hasErrorOrException(sv)))
- throw ErrorInfo(sv.toString(), configureScript->location());
+ throw ErrorInfo(m_engine->lastErrorString(sv), configureScript->location());
foreach (const ProbeProperty &b, probeBindings) {
const QVariant newValue = scope.property(b.first).toVariant();
if (newValue != b.second.toVariant())
diff --git a/src/lib/corelib/language/projectresolver.cpp b/src/lib/corelib/language/projectresolver.cpp
index a9435166c..715237c1d 100644
--- a/src/lib/corelib/language/projectresolver.cpp
+++ b/src/lib/corelib/language/projectresolver.cpp
@@ -1033,8 +1033,10 @@ QVariantMap ProjectResolver::evaluateProperties(Item *item, Item *propertiesCont
}
const QScriptValue scriptValue = m_evaluator->property(item, it.key());
- if (Q_UNLIKELY(m_evaluator->engine()->hasErrorOrException(scriptValue)))
- throw ErrorInfo(scriptValue.toString(), it.value()->location());
+ if (Q_UNLIKELY(m_evaluator->engine()->hasErrorOrException(scriptValue))) {
+ throw ErrorInfo(m_evaluator->engine()->lastErrorString(scriptValue),
+ it.value()->location());
+ }
// NOTE: Loses type information if scriptValue.isUndefined == true,
// as such QScriptValues become invalid QVariants.
diff --git a/src/lib/corelib/language/scriptengine.h b/src/lib/corelib/language/scriptengine.h
index 967820fa0..f69608d12 100644
--- a/src/lib/corelib/language/scriptengine.h
+++ b/src/lib/corelib/language/scriptengine.h
@@ -107,6 +107,10 @@ public:
bool hasErrorOrException(const QScriptValue &v) const {
return v.isError() || hasUncaughtException();
}
+ QScriptValue lastErrorValue(const QScriptValue &v) const {
+ return v.isError() ? v : uncaughtException();
+ }
+ QString lastErrorString(const QScriptValue &v) const { return lastErrorValue(v).toString(); }
void cancel();
diff --git a/src/lib/corelib/language/tst_language.cpp b/src/lib/corelib/language/tst_language.cpp
index af5166f2c..43fbf6dad 100644
--- a/src/lib/corelib/language/tst_language.cpp
+++ b/src/lib/corelib/language/tst_language.cpp
@@ -894,7 +894,7 @@ void TestLanguage::jsExtensions()
QScriptValue evaluated = m_engine->evaluate(code, file.fileName(), 1);
if (m_engine->hasErrorOrException(evaluated)) {
qDebug() << m_engine->uncaughtExceptionBacktrace();
- QFAIL(qPrintable(evaluated.toString()));
+ QFAIL(qPrintable(m_engine->lastErrorString(evaluated)));
}
}