Improve error reporting when parsing JSON files
At least report the error string and the file offset where the error happened. Change-Id: Iaa1733593b8af2a7a52b67c0f495731f045d2c11 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
parent
a11ced4981
commit
34c24ceb1f
@ -389,11 +389,16 @@ static void addJsonValue(const QJsonValue &value, const QString &keyPrefix, ProV
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static QMakeEvaluator::VisitReturn parseJsonInto(const QByteArray &json, const QString &into, ProValueMap *value)
|
QMakeEvaluator::VisitReturn QMakeEvaluator::parseJsonInto(const QByteArray &json, const QString &into, ProValueMap *value)
|
||||||
{
|
{
|
||||||
QJsonDocument document = QJsonDocument::fromJson(json);
|
QJsonParseError error;
|
||||||
if (document.isNull())
|
QJsonDocument document = QJsonDocument::fromJson(json, &error);
|
||||||
|
if (document.isNull()) {
|
||||||
|
if (error.error != QJsonParseError::NoError)
|
||||||
|
evalError(fL1S("Error parsing json at offset %1: %2")
|
||||||
|
.arg(error.offset).arg(error.errorString()));
|
||||||
return QMakeEvaluator::ReturnFalse;
|
return QMakeEvaluator::ReturnFalse;
|
||||||
|
}
|
||||||
|
|
||||||
QString currentKey = into + QLatin1Char('.');
|
QString currentKey = into + QLatin1Char('.');
|
||||||
|
|
||||||
|
@ -234,6 +234,7 @@ public:
|
|||||||
|
|
||||||
bool getMemberArgs(const ProKey &name, int srclen, const ProStringList &args,
|
bool getMemberArgs(const ProKey &name, int srclen, const ProStringList &args,
|
||||||
int *start, int *end);
|
int *start, int *end);
|
||||||
|
VisitReturn parseJsonInto(const QByteArray &json, const QString &into, ProValueMap *value);
|
||||||
|
|
||||||
VisitReturn writeFile(const QString &ctx, const QString &fn, QIODevice::OpenMode mode,
|
VisitReturn writeFile(const QString &ctx, const QString &fn, QIODevice::OpenMode mode,
|
||||||
bool exe, const QString &contents);
|
bool exe, const QString &contents);
|
||||||
|
@ -2162,7 +2162,7 @@ void tst_qmakelib::addTestFunctions(const QString &qindir)
|
|||||||
<< "jsontext = not good\n"
|
<< "jsontext = not good\n"
|
||||||
"parseJson(jsontext, json): OK = 1"
|
"parseJson(jsontext, json): OK = 1"
|
||||||
<< "OK = UNDEF"
|
<< "OK = UNDEF"
|
||||||
<< ""
|
<< "##:2: Error parsing json at offset 1: illegal value"
|
||||||
<< true;
|
<< true;
|
||||||
|
|
||||||
QTest::newRow("parseJson(): bad number of arguments")
|
QTest::newRow("parseJson(): bad number of arguments")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user