Future::value() should throw when unset
authorSimon Martin <simonmartin@fb.com>
Wed, 21 May 2014 20:31:54 +0000 (13:31 -0700)
committerAnton Likhtarov <alikhtarov@fb.com>
Mon, 9 Jun 2014 22:34:59 +0000 (15:34 -0700)
commit3bb510706c136314efae6899688de2c4246c0e9f
treeca95058f73be41c383a816e3b184c1ec887d4b43
parent206c8f8f75176a53b195677ea374844b252db83b
Future::value() should throw when unset

Summary:
Added a test to call Future::value() before the Promise value is set, expecting an exception.
In a dbg build the test failed due on the assertion in Optional::value().
In a opt build the test failed due as no exception was thrown.
There are 2 points where we could throw our exception:
a) Optional::value() - replacing the assertion
b) Future::value()

I'm not sure which location makes the most sense.
With the assertion in Optional it seems that adding the throw here would not be unexpected but this is outside the wangle code.
So as a first pass I've added the throw in Future::value(), and made a new WangleException for this.

Test Plan:
$ fbconfig folly/wangle
$ fbmake runtests

Reviewed By: hans@fb.com

Subscribers: folly@lists, fugalh

FB internal diff: D1340886
folly/wangle/WangleException.h
folly/wangle/detail.h
folly/wangle/test/FutureTest.cpp