mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 02:55:44 +08:00
refs #853, JSON exception handling in view base class
This commit is contained in:
committed by
Mathew Sutcliffe
parent
e3197ce375
commit
3939b0166f
@@ -1318,18 +1318,20 @@ namespace BlackGui
|
|||||||
tr("swift (*.json *.txt)"));
|
tr("swift (*.json *.txt)"));
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
{
|
{
|
||||||
m = CStatusMessage(this, CStatusMessage::SeverityDebug, "Load canceled", true);
|
m = CStatusMessage(this).error("Load canceled, no file name");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString json(CFileUtils::readFileToString(fileName));
|
const QString json(CFileUtils::readFileToString(fileName));
|
||||||
if (json.isEmpty())
|
if (json.isEmpty())
|
||||||
{
|
{
|
||||||
m = CStatusMessage(this, CStatusMessage::SeverityWarning, "Reading " + fileName + " yields no data", true);
|
m = CStatusMessage(this).warning("Reading '%1' yields no data") << fileName;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
ContainerType container;
|
ContainerType container;
|
||||||
container.convertFromJson(json); //! \todo catch CJsonException or use convertFromJsonNoThrow
|
container.convertFromJson(json);
|
||||||
m = this->modifyLoadedJsonData(container);
|
m = this->modifyLoadedJsonData(container);
|
||||||
if (m.isFailure()) { break; } // modification error
|
if (m.isFailure()) { break; } // modification error
|
||||||
m = this->validateLoadedJsonData(container);
|
m = this->validateLoadedJsonData(container);
|
||||||
@@ -1338,6 +1340,12 @@ namespace BlackGui
|
|||||||
m = CStatusMessage(this, CStatusMessage::SeverityInfo, "Reading " + fileName + " completed", true);
|
m = CStatusMessage(this, CStatusMessage::SeverityInfo, "Reading " + fileName + " completed", true);
|
||||||
this->jsonLoadedAndModelUpdated(container);
|
this->jsonLoadedAndModelUpdated(container);
|
||||||
}
|
}
|
||||||
|
catch (const CJsonException &ex)
|
||||||
|
{
|
||||||
|
m = ex.toStatusMessage(this, QString("Reading JSON from '%1'").arg(fileName));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
while (false);
|
while (false);
|
||||||
|
|
||||||
emit this->jsonLoadCompleted(m);
|
emit this->jsonLoadCompleted(m);
|
||||||
|
|||||||
Reference in New Issue
Block a user