Make script runtime errors appear in the script console
This commit is contained in:
parent
65ad9456dd
commit
748e599537
@ -38,12 +38,14 @@
|
|||||||
#include <qqml.h>
|
#include <qqml.h>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
|
|
||||||
|
#include <QMessageLogger>
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
Q_DECLARE_LOGGING_CATEGORY(dcScriptEngine)
|
Q_DECLARE_LOGGING_CATEGORY(dcScriptEngine)
|
||||||
|
|
||||||
namespace nymeaserver {
|
namespace nymeaserver {
|
||||||
namespace scriptengine {
|
namespace scriptengine {
|
||||||
|
|
||||||
|
|
||||||
ScriptAction::ScriptAction(QObject *parent) : QObject(parent)
|
ScriptAction::ScriptAction(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -130,7 +132,7 @@ void ScriptAction::execute(const QVariantMap ¶ms)
|
|||||||
things.append(thing);
|
things.append(thing);
|
||||||
}
|
}
|
||||||
if (things.isEmpty()) {
|
if (things.isEmpty()) {
|
||||||
qCWarning(dcScriptEngine) << "No things matching by id" << m_thingId << "and interface" << m_interfaceName;
|
QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "No things matching id" << m_thingId << "or interface" << m_interfaceName;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +144,7 @@ void ScriptAction::execute(const QVariantMap ¶ms)
|
|||||||
actionType = thing->thingClass().actionTypes().findByName(m_actionName);
|
actionType = thing->thingClass().actionTypes().findByName(m_actionName);
|
||||||
}
|
}
|
||||||
if (actionType.id().isNull()) {
|
if (actionType.id().isNull()) {
|
||||||
qCWarning(dcScriptEngine()) << "Thing" << thing->name() << "does not have actionTypeId" << m_actionTypeId << "or actionName" << m_actionName;
|
QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "Thing" << thing->name() << "does not have actionTypeId" << m_actionTypeId << "or actionName" << m_actionName;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Action action(actionType.id(), thing->id(), Action::TriggeredByScript);
|
Action action(actionType.id(), thing->id(), Action::TriggeredByScript);
|
||||||
@ -155,7 +157,7 @@ void ScriptAction::execute(const QVariantMap ¶ms)
|
|||||||
paramType = actionType.paramTypes().findByName(paramNameOrId);
|
paramType = actionType.paramTypes().findByName(paramNameOrId);
|
||||||
}
|
}
|
||||||
if (paramType.id().isNull()) {
|
if (paramType.id().isNull()) {
|
||||||
qCWarning(dcScriptEngine()) << "Invalid param id or name";
|
QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "Invalid param id or name:" << paramNameOrId;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
paramList << Param(paramType.id(), params.value(paramNameOrId));
|
paramList << Param(paramType.id(), params.value(paramNameOrId));
|
||||||
|
|||||||
@ -462,7 +462,7 @@ void ScriptEngine::onScriptMessage(QtMsgType type, const QMessageLogContext &con
|
|||||||
|
|
||||||
void ScriptEngine::logMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
|
void ScriptEngine::logMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
|
||||||
{
|
{
|
||||||
if (strcmp(context.category, "qml") != 0) {
|
if (strcmp(context.category, "qml") != 0 && strcmp(context.category, "ScriptRuntime") != 0) {
|
||||||
s_upstreamMessageHandler(type, context, message);
|
s_upstreamMessageHandler(type, context, message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -485,6 +485,7 @@ void ScriptEngine::logMessageHandler(QtMsgType type, const QMessageLogContext &c
|
|||||||
QFileInfo fi(context.file);
|
QFileInfo fi(context.file);
|
||||||
s_upstreamMessageHandler(type, newContext, fi.fileName() + ":" + QString::number(context.line) + ": " + message);
|
s_upstreamMessageHandler(type, newContext, fi.fileName() + ":" + QString::number(context.line) + ": " + message);
|
||||||
}
|
}
|
||||||
|
delete category;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::logCategoryFilter(QLoggingCategory *category)
|
void ScriptEngine::logCategoryFilter(QLoggingCategory *category)
|
||||||
|
|||||||
@ -89,6 +89,8 @@ public:
|
|||||||
EditScriptReply editScript(const QUuid &id, const QByteArray &content);
|
EditScriptReply editScript(const QUuid &id, const QByteArray &content);
|
||||||
ScriptError removeScript(const QUuid &id);
|
ScriptError removeScript(const QUuid &id);
|
||||||
|
|
||||||
|
void onScriptMessage(QtMsgType type, const QMessageLogContext &context, const QString &message);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void scriptAdded(const Script &script);
|
void scriptAdded(const Script &script);
|
||||||
void scriptRemoved(const QUuid &id);
|
void scriptRemoved(const QUuid &id);
|
||||||
@ -104,7 +106,6 @@ private:
|
|||||||
|
|
||||||
QString baseName(const QUuid &id);
|
QString baseName(const QUuid &id);
|
||||||
|
|
||||||
void onScriptMessage(QtMsgType type, const QMessageLogContext &context, const QString &message);
|
|
||||||
private:
|
private:
|
||||||
ThingManager *m_thingManager = nullptr;
|
ThingManager *m_thingManager = nullptr;
|
||||||
QQmlEngine *m_engine = nullptr;
|
QQmlEngine *m_engine = nullptr;
|
||||||
|
|||||||
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include <qqml.h>
|
#include <qqml.h>
|
||||||
|
#include <QQmlContext>
|
||||||
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
Q_DECLARE_LOGGING_CATEGORY(dcScriptEngine)
|
Q_DECLARE_LOGGING_CATEGORY(dcScriptEngine)
|
||||||
@ -94,14 +95,14 @@ void ScriptInterfaceAction::execute(const QVariantMap ¶ms)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (things.isEmpty()) {
|
if (things.isEmpty()) {
|
||||||
qCWarning(dcScriptEngine) << "No things matching by interface" << m_interfaceName;
|
QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "No things matching by interface" << m_interfaceName;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Thing *thing, things) {
|
foreach (Thing *thing, things) {
|
||||||
ActionType actionType = thing->thingClass().actionTypes().findByName(m_actionName);
|
ActionType actionType = thing->thingClass().actionTypes().findByName(m_actionName);
|
||||||
if (actionType.id().isNull()) {
|
if (actionType.id().isNull()) {
|
||||||
qCWarning(dcScriptEngine()) << "Thing" << thing->name() << "does not have action" << m_actionName;
|
QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "Thing" << thing->name() << "does not have action" << m_actionName;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Action action(actionType.id(), thing->id(), Action::TriggeredByScript);
|
Action action(actionType.id(), thing->id(), Action::TriggeredByScript);
|
||||||
@ -114,7 +115,7 @@ void ScriptInterfaceAction::execute(const QVariantMap ¶ms)
|
|||||||
paramType = actionType.paramTypes().findByName(paramNameOrId);
|
paramType = actionType.paramTypes().findByName(paramNameOrId);
|
||||||
}
|
}
|
||||||
if (paramType.id().isNull()) {
|
if (paramType.id().isNull()) {
|
||||||
qCWarning(dcScriptEngine()) << "Invalid param id or name";
|
QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "Invalid param id or name";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
paramList << Param(paramType.id(), params.value(paramNameOrId));
|
paramList << Param(paramType.id(), params.value(paramNameOrId));
|
||||||
|
|||||||
@ -160,19 +160,19 @@ void ScriptState::setValue(const QVariant &value)
|
|||||||
if (!m_stateTypeId.isNull()) {
|
if (!m_stateTypeId.isNull()) {
|
||||||
actionTypeId = thing->thingClass().stateTypes().findById(StateTypeId(m_stateTypeId)).id();
|
actionTypeId = thing->thingClass().stateTypes().findById(StateTypeId(m_stateTypeId)).id();
|
||||||
if (actionTypeId.isNull()) {
|
if (actionTypeId.isNull()) {
|
||||||
qCDebug(dcScriptEngine) << "Thing" << thing->name() << "does not have a state with type id" << m_stateTypeId;
|
QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "Thing" << thing->name() << "does not have a state with type id" << m_stateTypeId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (actionTypeId.isNull()) {
|
if (actionTypeId.isNull()) {
|
||||||
actionTypeId = thing->thingClass().stateTypes().findByName(stateName()).id();
|
actionTypeId = thing->thingClass().stateTypes().findByName(stateName()).id();
|
||||||
if (actionTypeId.isNull()) {
|
if (actionTypeId.isNull()) {
|
||||||
qCDebug(dcScriptEngine) << "Thing" << thing->name() << "does not have a state named" << m_stateName;
|
QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "Thing" << thing->name() << "does not have a state named" << m_stateName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionTypeId.isNull()) {
|
if (actionTypeId.isNull()) {
|
||||||
m_valueCache = value;
|
m_valueCache = value;
|
||||||
qCDebug(dcScriptEngine()) << "Either stateTypeId or stateName is required to be valid.";
|
QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "Either stateTypeId or stateName is required to be valid.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,6 +33,7 @@
|
|||||||
#include <qqml.h>
|
#include <qqml.h>
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
#include <QQmlContext>
|
||||||
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
Q_DECLARE_LOGGING_CATEGORY(dcScriptEngine)
|
Q_DECLARE_LOGGING_CATEGORY(dcScriptEngine)
|
||||||
@ -112,7 +113,7 @@ void ScriptThing::executeAction(const QString &actionName, const QVariantMap &pa
|
|||||||
actionType = thing->thingClass().actionTypes().findById(QUuid(actionName));
|
actionType = thing->thingClass().actionTypes().findById(QUuid(actionName));
|
||||||
}
|
}
|
||||||
if (actionType.id().isNull()) {
|
if (actionType.id().isNull()) {
|
||||||
qCWarning(dcScriptEngine()) << "Thing" << thing->name() << "does not have action" << actionName;
|
QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "Thing" << thing->name() << "does not have action" << actionName;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +127,7 @@ void ScriptThing::executeAction(const QString &actionName, const QVariantMap &pa
|
|||||||
paramType = actionType.paramTypes().findByName(paramNameOrId);
|
paramType = actionType.paramTypes().findByName(paramNameOrId);
|
||||||
}
|
}
|
||||||
if (paramType.id().isNull()) {
|
if (paramType.id().isNull()) {
|
||||||
qCWarning(dcScriptEngine()) << "Invalid param id or name";
|
QMessageLogger(qmlEngine(this)->contextForObject(this)->baseUrl().toString().toUtf8(), 0, "", "qml").warning() << "Invalid param id or name:" << paramNameOrId;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
paramList << Param(paramType.id(), params.value(paramNameOrId));
|
paramList << Param(paramType.id(), params.value(paramNameOrId));
|
||||||
|
|||||||
Reference in New Issue
Block a user