serverInit uses explicit errors, not exceptions
commit8e7179eb199ac7014ad6d7763d21fd71f7f25398
authorLucian Wischik <ljw@fb.com>
Tue, 2 Oct 2018 03:17:04 +0000 (1 20:17 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Tue, 2 Oct 2018 03:18:44 +0000 (1 20:18 -0700)
tree700b68a731de09b706a86bd65e457276a19c8823
parented9016c720c7ed2c2e47135cffd576789f8f8305
serverInit uses explicit errors, not exceptions

Summary:
This diff is the first step in using error ADTs rather than exceptions. (the rest of the cases are done in a future diff).

We already use ADTs for errors in other places like State_loader and Future.

The main reason is so we can take advantage of ocaml exhaustivity checks to be sure we've covered all cases; logging will derive a similar benefit. (This is part of a bigger project to track down and eliminate/control all sources of errors for loading saved-state).

Anyway, here's what this diff changes:

(1) We use an ADT for errors arising from serverInit, rather than exn.

(2) The INIT_LAZY_END and LOAD_MINI_EXN events now have more specific and richer information.

(3) The Hh_logger, after its message "Could not load mini state:", now also prints that more specific and richer information. The string "Could not load mini state" is regexp-matched elsewhere, and I'm not changing it.

(4) The function `invoke_loading_state_natively` returns a lambda which, when invoked, returns a `result`. It used to [A] raise some exceptions eagerly upon invocation of method, and then [B] produce exceptions/errors upon invocation of the lambda. I changed it so that all fault conditions, both errors and exceptions, both those discovered eagerly and those discovered upon invocation of the lambda, are all now returned in the `result`.

What's the impact of part (4)? Well, it goes down to the `invoke_approach` function. It returns a double-lambda where invoking the first would produce [A], and invoking the second would produce [B]. The only place where those double-lambdas were ever invoked was one immediately after the other, in ServerLazyInit.init. So the effect of this change is merely that errors will be logged with slightly different verbose strings in HackEventLogger.

What's the significance of part (4)? Well, there's no real justification for returning a double-lambda that lets the caller break up its execution into two phases. We should merely return a single lambda. This diff is a step towards that.

Reviewed By: dabek

Differential Revision: D10100665

fbshipit-source-id: ff9df7232699d7e22c0e9fd57bc040f1e0601143
hphp/hack/src/server/serverInit.ml