Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a custom eigen_assert macro #3080

Open
WardBrian opened this issue May 31, 2024 · 0 comments
Open

Add a custom eigen_assert macro #3080

WardBrian opened this issue May 31, 2024 · 0 comments

Comments

@WardBrian
Copy link
Member

Description

Eigen assertions from Stan code are always indicative of a bug (see #3075, most recently) but they lack any contextual information about where the assertion occurs. We can inject this ourselves using the Boost.Stacktrace library, which would make reports much easier to debug.

For example, this code seems to work on Linux:

#define BOOST_STACKTRACE_USE_ADDR2LINE 1

#include <stdexcept>
#include <iostream>
#include <boost/stacktrace.hpp>
#undef eigen_assert
#define eigen_assert(x) \
  if (!(x)) { std::cerr << boost::stacktrace::stacktrace() << std::endl;\
               throw (std::runtime_error("Eigen assertion failed! Please report a bug to Stan")); }

This will report both the C++ traceback, and because it is a normal exception, the location in the Stan source file which triggered it.

Boost.Stacktrace does require some extra libraries, which are pre-installed on *Nix-like, but may not be on Windows, so we may want to add the above behind a STAN_DEBUG flag or similar.

Current Version:

v4.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant