Skip to content

Commit

Permalink
Reset controller state on failed model build (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
elihart authored Apr 2, 2019
1 parent 990f199 commit ee0755a
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,24 @@ public void run() {
modelsBeingBuilt = new ControllerModelList(getExpectedModelCount());

timer.start("Models built");
buildModels();

// The user's implementation of buildModels is wrapped in a try/catch so that if it fails
// we can reset the state of this controller. This is useful when model building is done
// on a dedicated thread, which may have its own error handler, and a failure may not
// crash the app - in which case this controller would be in an invalid state and crash later
// with confusing errors because "threadBuildingModels" and other properties are not
// correctly set. This can happen particularly with Espresso testing.
try {
buildModels();
} catch (Throwable throwable) {
timer.stop();
modelsBeingBuilt = null;
hasBuiltModelsEver = true;
threadBuildingModels = null;
stagedModel = null;
throw throwable;
}

addCurrentlyStagedModelIfExists();
timer.stop();

Expand Down

0 comments on commit ee0755a

Please sign in to comment.