Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset controller state on failed model build #720

Merged
merged 1 commit into from
Apr 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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