Skip to content

Commit

Permalink
Expression class: Improved error message when resolving a variable fa…
Browse files Browse the repository at this point in the history
…ils.
  • Loading branch information
eivindkv authored and wwmayer committed Feb 18, 2016
1 parent be67125 commit 1da5d33
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/App/Expression.cpp
Expand Up @@ -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());
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/App/ObjectIdentifier.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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 "";
}
4 changes: 4 additions & 0 deletions src/App/ObjectIdentifier.h
Expand Up @@ -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 {
Expand All @@ -242,6 +244,8 @@ class AppExport ObjectIdentifier {
String resolvedDocumentObjectName;
App::Property * resolvedProperty;
std::string propertyName;

std::string resolveErrorString() const;
};

std::string getPythonAccessor() const;
Expand Down

0 comments on commit 1da5d33

Please sign in to comment.