Pretty-print missing recipientId crashes.

This commit is contained in:
Greyson Parrelli 2019-10-02 12:06:13 -04:00
parent 5e1bef26ed
commit af96d11188
2 changed files with 17 additions and 2 deletions

View File

@ -270,7 +270,7 @@ public class RecipientDatabase extends Database {
if (cursor != null && cursor.moveToNext()) {
return getRecipientSettings(cursor);
} else {
throw new AssertionError("Couldn't find recipient! id: " + id.serialize());
throw new MissingRecipientError(id);
}
}
}
@ -879,4 +879,9 @@ public class RecipientDatabase extends Database {
}
}
public static class MissingRecipientError extends AssertionError {
public MissingRecipientError(@Nullable RecipientId id) {
super("Failed to find recipient with ID: " + id);
}
}
}

View File

@ -10,6 +10,7 @@ import androidx.lifecycle.MutableLiveData;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.RecipientDatabase;
import org.thoughtcrime.securesms.database.RecipientDatabase.MissingRecipientError;
import org.thoughtcrime.securesms.util.LRUCache;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.concurrent.SignalExecutors;
@ -44,7 +45,16 @@ public final class LiveRecipientCache {
final LiveRecipient newLive = new LiveRecipient(context, new MutableLiveData<>(), new Recipient(id));
recipients.put(id, newLive);
SignalExecutors.BOUNDED.execute(newLive::resolve);
MissingRecipientError prettyStackTraceError = new MissingRecipientError(newLive.getId());
SignalExecutors.BOUNDED.execute(() -> {
try {
newLive.resolve();
} catch (MissingRecipientError e) {
throw prettyStackTraceError;
}
});
live = newLive;
}