Implemented error checks for parsing the JSON file

This commit is contained in:
2025-02-07 20:20:04 +02:00
parent a458d82577
commit 09b1e17de0

View File

@ -9,7 +9,17 @@ UserList loadUserList(const QString &file)
{
QFile doc{std::filesystem::path{file.toStdString()}};
QString fileContents = doc.readAll();
QJsonDocument document = QJsonDocument::fromJson(fileContents.toUtf8());
QJsonParseError errors;
QJsonDocument document =
QJsonDocument::fromJson(fileContents.toUtf8(),
&errors);
if (document.isNull())
{
qDebug() << errors.errorString();
throw std::runtime_error{"Could not parse JSON file"};
}
QJsonArray array = document.array();
QVector<User> container;