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:
wmayer
2025-03-01 08:36:05 +01:00
committed by Ladislav Michl
parent 3fba587044
commit 56e687d9cc
2 changed files with 26 additions and 9 deletions

View File

@@ -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);

View File

@@ -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;