App: Refactor PropertyExpressionEngine::afterRestore()
Put the reading of each expression of an object into a try/catch block. This is to avoid that all expressions of an object may be lost. This mitigates the issue 19866
This commit is contained in:
@@ -467,21 +467,36 @@ void PropertyExpressionEngine::afterRestore()
|
||||
ObjectIdentifier::DocumentMapper mapper(this->_DocMap);
|
||||
|
||||
for (auto& info : *restoredExpressions) {
|
||||
ObjectIdentifier path = ObjectIdentifier::parse(docObj, info.path);
|
||||
if (!info.expr.empty()) {
|
||||
std::shared_ptr<Expression> expression(
|
||||
Expression::parse(docObj, info.expr.c_str()));
|
||||
if (expression) {
|
||||
expression->comment = std::move(info.comment);
|
||||
}
|
||||
setValue(path, expression);
|
||||
}
|
||||
tryRestoreExpression(docObj, info);
|
||||
}
|
||||
signaller.tryInvoke();
|
||||
}
|
||||
restoredExpressions.reset();
|
||||
}
|
||||
|
||||
void PropertyExpressionEngine::tryRestoreExpression(DocumentObject* docObj,
|
||||
const RestoredExpression& info)
|
||||
{
|
||||
try {
|
||||
ObjectIdentifier path = ObjectIdentifier::parse(docObj, info.path);
|
||||
if (!info.expr.empty()) {
|
||||
std::shared_ptr<Expression> expression(
|
||||
Expression::parse(docObj, info.expr));
|
||||
if (expression) {
|
||||
expression->comment = info.comment;
|
||||
}
|
||||
setValue(path, expression);
|
||||
}
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
FC_ERR("Failed to restore " << docObj->getFullName()
|
||||
<< '.'
|
||||
<< getName()
|
||||
<< ": "
|
||||
<< e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyExpressionEngine::onContainerRestored()
|
||||
{
|
||||
Base::FlagToggler<bool> flag(restoring);
|
||||
|
||||
@@ -244,6 +244,8 @@ private:
|
||||
* into the actual map */
|
||||
std::unique_ptr<std::vector<RestoredExpression>> restoredExpressions;
|
||||
|
||||
void tryRestoreExpression(DocumentObject* docObj, const RestoredExpression& info);
|
||||
|
||||
struct Private;
|
||||
std::unique_ptr<Private> pimpl;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user