Commit ce403dac authored by Dhruv Matani's avatar Dhruv Matani Committed by facebook-github-bot-1

More descriptive message when we fail with a "Double registration of singleton" error

Summary: When we FATAL with a "Double registration of singleton" error, make it abundantly clear why such a thing could have happended so that the developer doesn't feel lost.

Reviewed By: @chipturner

Differential Revision: D2345728
parent e71c842c
......@@ -32,7 +32,26 @@ void SingletonHolder<T>::registerSingleton(CreateFunc c, TeardownFunc t) {
std::lock_guard<std::mutex> entry_lock(mutex_);
if (state_ != SingletonHolderState::NotRegistered) {
LOG(FATAL) << "Double registration of singleton: " << type_.name();
/* Possible causes:
*
* You have two instances of the same
* folly::Singleton<Class>. Probably because you define the
* singleton in a header included in multiple places? In general,
* folly::Singleton shouldn't be in the header, only off in some
* anonymous namespace in a cpp file. Code needing the singleton
* will find it when that code references folly::Singleton<Class>.
*
* Alternatively, you could have 2 singletons with the same type
* defined with a different name in a .cpp (source) file. For
* example:
*
* Singleton<int> a([] { return new int(3); });
* Singleton<int> b([] { return new int(4); });
*
*/
LOG(FATAL) << "Double registration of singletons of the same "
<< "underlying type; check for multiple definitions "
<< "of type folly::Singleton<" + type_.name() + ">";
}
create_ = std::move(c);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment