From: Dhruv Matani Date: Sat, 15 Aug 2015 15:37:23 +0000 (-0700) Subject: More descriptive message when we fail with a "Double registration of singleton" error X-Git-Tag: v0.54.0~5 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=ce403dac41c9b99eeaa6d5aea4c5b543da05c149 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 --- diff --git a/folly/Singleton-inl.h b/folly/Singleton-inl.h index 3848ab44..d3e6ea30 100644 --- a/folly/Singleton-inl.h +++ b/folly/Singleton-inl.h @@ -32,7 +32,26 @@ void SingletonHolder::registerSingleton(CreateFunc c, TeardownFunc t) { std::lock_guard 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. 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. + * + * Alternatively, you could have 2 singletons with the same type + * defined with a different name in a .cpp (source) file. For + * example: + * + * Singleton a([] { return new int(3); }); + * Singleton 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);