Skip to content

Commit

Permalink
Merge pull request #2018 from dimagi/duplicateFormId
Browse files Browse the repository at this point in the history
Adds crash log for Unique form id constraint failure
  • Loading branch information
shubham1g5 authored Jul 9, 2018
2 parents 88493b2 + fbef2cd commit e87ccbe
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions app/src/org/commcare/models/AndroidSessionWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import android.util.Log;

import org.commcare.CommCareApplication;
import org.commcare.models.database.SqlStorage;
import org.commcare.android.database.user.models.FormRecord;
import org.commcare.android.database.user.models.SessionStateDescriptor;
import org.commcare.models.database.SqlStorage;
import org.commcare.modern.session.SessionWrapperInterface;
import org.commcare.preferences.HiddenPreferences;
import org.commcare.session.CommCareSession;
Expand All @@ -20,6 +20,7 @@
import org.commcare.util.CommCarePlatform;
import org.commcare.utils.AndroidInstanceInitializer;
import org.commcare.utils.CommCareUtil;
import org.commcare.utils.CrashUtil;
import org.javarosa.core.model.condition.EvaluationContext;

import java.util.Date;
Expand Down Expand Up @@ -198,7 +199,14 @@ public void commitStub() {
setFormRecordId(r.getID());

SessionStateDescriptor ssd = SessionStateDescriptor.buildFromSessionWrapper(this);
sessionStorage.write(ssd);
try {
sessionStorage.write(ssd);
} catch (Exception e) {
if (ssd != null) {
CrashUtil.log("SessionStateDescriptor form id: " + ssd.getFormRecordId());
}
throw e;
}
sessionStateRecordId = ssd.getID();
}

Expand Down Expand Up @@ -226,13 +234,13 @@ public EvaluationContext getRestrictedEvaluationContext(String commandId,
public EvaluationContext getEvaluationContext(String commandId) {
return session.getEvaluationContext(getIIF(), commandId, null);
}

private AndroidInstanceInitializer initializer;

public AndroidInstanceInitializer getIIF() {
if (initializer == null) {
initializer = new AndroidInstanceInitializer(session);
}
}

return initializer;
}
Expand Down Expand Up @@ -265,7 +273,7 @@ public static AndroidSessionWrapper mockEasiestRoute(CommCarePlatform platform,
if (datum instanceof ComputedDatum) {
// Allow mocking of routes that need computed data, useful for case creation forms
wrapper = new AndroidSessionWrapper(platform);
wrapper.session.setCommand(platform.getModuleNameForEntry((FormEntry) e));
wrapper.session.setCommand(platform.getModuleNameForEntry((FormEntry)e));
wrapper.session.setCommand(e.getCommandId());
wrapper.session.setComputedDatum(wrapper.getEvaluationContext());
} else if (datum instanceof EntityDatum) {
Expand All @@ -287,7 +295,7 @@ public static AndroidSessionWrapper mockEasiestRoute(CommCarePlatform platform,
}

wrapper = new AndroidSessionWrapper(platform);
wrapper.session.setCommand(platform.getModuleNameForEntry((FormEntry) e));
wrapper.session.setCommand(platform.getModuleNameForEntry((FormEntry)e));
wrapper.session.setCommand(e.getCommandId());
wrapper.session.setDatum(entityDatum.getDataId(), selectedValue);
}
Expand Down

0 comments on commit e87ccbe

Please sign in to comment.