print custom error message if type names match

release/4.3a0
Varun Agrawal 2020-05-19 17:34:07 -05:00
parent baaa656628
commit 14ccd06bf2
2 changed files with 16 additions and 5 deletions

View File

@ -44,7 +44,7 @@ std::string demangle(const char* name) {
int status = -1; // some arbitrary value to eliminate the compiler warning
demangled = abi::__cxa_demangle(name, nullptr, nullptr, &status),
demangled_name = (status == 0) ? std::string(demangled) : name;
demangled_name = (status == 0) ? std::string(demangled) : std::string(name);
std::free(demangled);

View File

@ -232,10 +232,21 @@ namespace gtsam {
/* ************************************************************************* */
const char* ValuesIncorrectType::what() const throw() {
if(message_.empty())
message_ =
"Attempting to retrieve value with key \"" + DefaultKeyFormatter(key_) + "\", type stored in Values is " +
std::string(demangle(storedTypeId_.name())) + " but requested type was " + std::string(demangle(requestedTypeId_.name()));
if(message_.empty()) {
std::string storedTypeName = demangle(storedTypeId_.name());
std::string requestedTypeName = demangle(requestedTypeId_.name());
if (storedTypeName == requestedTypeName) {
message_ = "WARNING: Detected types with same name but different `typeid`. \
This is usually caused by incorrect linking/inlining settings when compiling libraries using GTSAM. \
If you are a user, please report to the author of the library using GTSAM. \
If you are a package maintainer, please consult `cmake/GtsamPybindWrap.cmake`, line 74 for details.";
} else {
message_ =
"Attempting to retrieve value with key \"" + DefaultKeyFormatter(key_) + "\", type stored in Values is " +
storedTypeName + " but requested type was " + requestedTypeName;
}
}
return message_.c_str();
}