GH-1453 report version file problems in the version page

This commit is contained in:
Petr Mrázek
2016-02-21 01:44:27 +01:00
parent 495d320ce2
commit 1a0bbdd9ac
11 changed files with 305 additions and 26 deletions

View File

@@ -107,13 +107,26 @@ VersionFilePtr parseJsonFile(const QFileInfo &fileInfo, const bool requireOrder)
.arg(fileInfo.fileName(), file.errorString()));
}
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &error);
auto data = file.readAll();
QJsonDocument doc = QJsonDocument::fromJson(data, &error);
if (error.error != QJsonParseError::NoError)
{
int line = 0;
int column = 0;
for(int i = 0; i < error.offset; i++)
{
if(data[i] == '\n')
{
line++;
column = 0;
continue;
}
column++;
}
throw JSONValidationError(
QObject::tr("Unable to process the version file %1: %2 at %3.")
QObject::tr("Unable to process the version file %1: %2 at line %3 column %4.")
.arg(fileInfo.fileName(), error.errorString())
.arg(error.offset));
.arg(line).arg(column));
}
return VersionFile::fromJson(doc, file.fileName(), requireOrder);
}