diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index f11d80e2e129..149de08a714c 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -989,7 +989,7 @@ const Property * VariableExpression::getProperty() const if (prop) return prop; else - throw ExpressionError(std::string("Property '") + var.getPropertyName() + std::string("' not found.")); + throw Expression::Exception(var.resolveErrorString().c_str()); } /** diff --git a/src/App/ObjectIdentifier.cpp b/src/App/ObjectIdentifier.cpp index 586cbe6e26d8..0b089176b0cb 100644 --- a/src/App/ObjectIdentifier.cpp +++ b/src/App/ObjectIdentifier.cpp @@ -865,6 +865,13 @@ ObjectIdentifier ObjectIdentifier::parse(const DocumentObject *docObj, const std throw Base::Exception("Invalid property specification."); } +std::string ObjectIdentifier::resolveErrorString() const +{ + ResolveResults result(*this); + + return result.resolveErrorString(); +} + /** * @brief << operator, used to add a component to the object identifier. * @param value Component object @@ -1111,3 +1118,17 @@ ObjectIdentifier::ResolveResults::ResolveResults(const ObjectIdentifier &oi) { oi.resolve(*this); } + +std::string ObjectIdentifier::ResolveResults::resolveErrorString() const +{ + if (resolvedDocument == 0) + return std::string("Document not found: ") + resolvedDocumentName.toString(); + else if (resolvedDocumentObject == 0) + return std::string("Document object not found: ") + resolvedDocumentObjectName.toString(); + else if (resolvedProperty == 0) + return std::string("Property not found: ") + propertyName; + + assert(false); + + return ""; +} diff --git a/src/App/ObjectIdentifier.h b/src/App/ObjectIdentifier.h index c838f3be4f69..d28b1cfd4579 100644 --- a/src/App/ObjectIdentifier.h +++ b/src/App/ObjectIdentifier.h @@ -229,6 +229,8 @@ class AppExport ObjectIdentifier { static ObjectIdentifier parse(const App::DocumentObject *docObj, const std::string & str); + std::string resolveErrorString() const; + protected: struct ResolveResults { @@ -242,6 +244,8 @@ class AppExport ObjectIdentifier { String resolvedDocumentObjectName; App::Property * resolvedProperty; std::string propertyName; + + std::string resolveErrorString() const; }; std::string getPythonAccessor() const;