From: Chip Turner Date: Thu, 7 Aug 2014 13:19:22 +0000 (-0700) Subject: Improve messaging when registrationComplete hasn't been called X-Git-Tag: v0.22.0~382 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=c715a583965f84f44aa4613c03b58e2a5c9d53c3;hp=9b4749fd47c605c27b6973f317d7c4f3a0e101e9;p=folly.git Improve messaging when registrationComplete hasn't been called Summary: The previous message from CHECK_THROW was difficult to debug. This improves the messaging to be more actionable. Test Plan: runtests Reviewed By: lins@fb.com Subscribers: lins, anca, fugalh FB internal diff: D1483915 --- diff --git a/folly/experimental/Singleton.h b/folly/experimental/Singleton.h index aa3130fe..0c12519b 100644 --- a/folly/experimental/Singleton.h +++ b/folly/experimental/Singleton.h @@ -138,7 +138,12 @@ class SingletonVault { // Retrieve a singleton from the vault, creating it if necessary. std::shared_ptr get_shared(const std::type_info& type) { std::unique_lock lock(mutex_); - CHECK_THROW(state_ == SingletonVaultState::Running, std::logic_error); + if (state_ != SingletonVaultState::Running) { + throw std::logic_error( + "Attempt to load a singleton before " + "SingletonVault::registrationComplete was called (hint: you probably " + "didn't call initFacebook)"); + } auto it = singletons_.find(type); if (it == singletons_.end()) {