Skip to content

Commit dccb3f0

Browse files
authored
Merge pull request #3544 from dimagi/hotfix_add-troubleshooting-logs-aroud-case-list-loading-crash
[Hotfix] Add troubleshooting logging about case list loading crash
2 parents cbf93ac + 2a9d3f1 commit dccb3f0

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

app/src/org/commcare/services/CommCareSessionService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ public void startSession(User user, UserKeyRecord record) {
266266
}
267267
}
268268

269+
public Date getSessionExpireDate() {
270+
return sessionExpireDate;
271+
}
272+
269273
private void setUpSessionExpirationTimer() {
270274
maintenanceTimer = new Timer("CommCareService");
271275
maintenanceTimer.schedule(new TimerTask() {

app/src/org/commcare/tasks/EntityLoaderHelper.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ import org.javarosa.core.model.instance.TreeReference
2222
*/
2323
class EntityLoaderHelper(
2424
detail: Detail,
25-
sessionDatum: EntityDatum?,
25+
var sessionDatum: EntityDatum?,
2626
evalCtx: EvaluationContext,
2727
inBackground: Boolean,
28-
var factory: NodeEntityFactory? = null
28+
var factory: NodeEntityFactory? = null,
2929
) : Cancellable {
30-
3130
var focusTargetIndex: Int = -1
3231
private var stopLoading: Boolean = false
3332

@@ -57,11 +56,15 @@ class EntityLoaderHelper(
5756
*/
5857
fun loadEntities(
5958
nodeset: TreeReference,
60-
progressListener: EntityLoadingProgressListener
59+
progressListener: EntityLoadingProgressListener,
6160
): Pair<List<Entity<TreeReference>>, List<TreeReference>>? {
6261
if (!isAsyncNodeEntityFactory()) {
6362
// if we are into synchronous mode, cancel background cache work for now to not lock the user db
64-
CommCareApplication.instance().currentApp.primeEntityCacheHelper.cancelWork()
63+
CommCareApplication
64+
.instance()
65+
.currentApp
66+
.primeEntityCacheHelper
67+
.cancelWork()
6568
}
6669
try {
6770
val references = factory!!.expandReferenceList(nodeset)
@@ -80,9 +83,7 @@ class EntityLoaderHelper(
8083
return null
8184
}
8285

83-
fun isAsyncNodeEntityFactory(): Boolean {
84-
return factory is AsyncNodeEntityFactory
85-
}
86+
fun isAsyncNodeEntityFactory(): Boolean = factory is AsyncNodeEntityFactory
8687

8788
/**
8889
* Primes the entity cache
@@ -103,7 +104,7 @@ class EntityLoaderHelper(
103104
*/
104105
private fun loadEntitiesWithReferences(
105106
references: List<TreeReference>,
106-
progressListener: EntityLoadingProgressListener?
107+
progressListener: EntityLoadingProgressListener?,
107108
): MutableList<Entity<TreeReference>>? {
108109
val entities: MutableList<Entity<TreeReference>> = ArrayList()
109110
focusTargetIndex = -1
@@ -115,7 +116,7 @@ class EntityLoaderHelper(
115116
progressListener?.publishEntityLoadingProgress(
116117
EntityLoadingProgressListener.EntityLoadingProgressPhase.PHASE_PROCESSING,
117118
index,
118-
references.size
119+
references.size,
119120
)
120121
val e = factory!!.getEntity(ref)
121122
if (e != null) {

app/src/org/commcare/tasks/EntityLoaderTask.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.google.firebase.perf.metrics.Trace;
66

7+
import org.commcare.CommCareApplication;
78
import org.commcare.android.logging.ForceCloseLogger;
89
import org.commcare.cases.entity.Entity;
910
import org.commcare.cases.entity.EntityLoadingProgressListener;
@@ -12,11 +13,13 @@
1213
import org.commcare.suite.model.Detail;
1314
import org.commcare.suite.model.EntityDatum;
1415
import org.commcare.tasks.templates.ManagedAsyncTask;
16+
import org.commcare.util.LogTypes;
1517
import org.javarosa.core.model.condition.EvaluationContext;
1618
import org.javarosa.core.model.instance.TreeReference;
1719
import org.javarosa.core.services.Logger;
1820
import org.javarosa.xpath.XPathException;
1921

22+
import java.util.Date;
2023
import java.util.HashMap;
2124
import java.util.List;
2225
import java.util.Map;
@@ -79,9 +82,29 @@ protected Pair<List<Entity<TreeReference>>, List<TreeReference>> doInBackground(
7982
Logger.exception("Error during EntityLoaderTask: " + ForceCloseLogger.getStackTrace(xe), xe);
8083
mException = xe;
8184
return null;
85+
} catch (RuntimeException e) {
86+
Logger.log(LogTypes.SOFT_ASSERT, "Loading entities failed for " + getSessionShortDetail() +
87+
"; session expiring at: " + getSessionExpirationTime());
88+
throw e;
8289
}
8390
}
8491

92+
private Date getSessionExpirationTime() {
93+
if (CommCareApplication.isSessionActive()) {
94+
try {
95+
return CommCareApplication.instance().getSession().getSessionExpireDate();
96+
} catch (Exception e) {
97+
return null;
98+
}
99+
}
100+
return null;
101+
}
102+
103+
private String getSessionShortDetail() {
104+
return (entityLoaderHelper != null && entityLoaderHelper.getSessionDatum() != null) ?
105+
entityLoaderHelper.getSessionDatum().getShortDetail() : "null";
106+
}
107+
85108
@Override
86109
protected void onPostExecute(Pair<List<Entity<TreeReference>>, List<TreeReference>> result) {
87110
super.onPostExecute(result);

0 commit comments

Comments
 (0)