Properly report observable returning nullptr
authorAndrii Grynenko <andrii@fb.com>
Wed, 31 Aug 2016 21:12:57 +0000 (14:12 -0700)
committerFacebook Github Bot 6 <facebook-github-bot-6-bot@fb.com>
Wed, 31 Aug 2016 21:23:32 +0000 (14:23 -0700)
Summary: Make sure exception is propagated to caller (especially when Observer is just created).

Reviewed By: yfeldblum

Differential Revision: D3798991

fbshipit-source-id: cee8452cfd40dcfbaf0e2ae2c2ee628af0362c6e

folly/experimental/observer/Observable-inl.h

index 75061ac27d3b970d9d169be10b1eda11612b8673..9bd3c83d8868d36a115077a4df6ed8cc00a2177a 100644 (file)
@@ -42,7 +42,9 @@ class ObserverCreator<Observable, Traits>::Context {
   void update() {
     {
       auto newValue = Traits::get(observable_);
-      DCHECK(newValue);
+      if (!newValue) {
+        throw std::logic_error("Observable returned nullptr.");
+      }
       value_.swap(newValue);
     }