From 56e687d9cc8a62cf0c66b109cc89a13348e514ac Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 1 Mar 2025 08:36:05 +0100 Subject: [PATCH] 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 --- src/App/PropertyExpressionEngine.cpp | 33 ++++++++++++++++++++-------- src/App/PropertyExpressionEngine.h | 2 ++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/App/PropertyExpressionEngine.cpp b/src/App/PropertyExpressionEngine.cpp index 241a93ead7..c0fa969562 100644 --- a/src/App/PropertyExpressionEngine.cpp +++ b/src/App/PropertyExpressionEngine.cpp @@ -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::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::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 flag(restoring); diff --git a/src/App/PropertyExpressionEngine.h b/src/App/PropertyExpressionEngine.h index b1d83e0a56..6322892347 100644 --- a/src/App/PropertyExpressionEngine.h +++ b/src/App/PropertyExpressionEngine.h @@ -244,6 +244,8 @@ private: * into the actual map */ std::unique_ptr> restoredExpressions; + void tryRestoreExpression(DocumentObject* docObj, const RestoredExpression& info); + struct Private; std::unique_ptr pimpl;