Skip to content

Commit 4904c20

Browse files
committed
Send debug information to Crashlytics when no active book is found
1 parent c27f763 commit 4904c20

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

app/src/main/java/org/gnucash/android/db/adapter/BooksDbAdapter.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import android.net.Uri;
2525
import android.support.annotation.NonNull;
2626

27+
import com.crashlytics.android.Crashlytics;
28+
2729
import org.gnucash.android.R;
2830
import org.gnucash.android.app.GnuCashApplication;
2931
import org.gnucash.android.db.DatabaseSchema.BookEntry;
@@ -155,15 +157,32 @@ public boolean isActive(String bookUID){
155157
Cursor cursor = mDb.query(mTableName, new String[]{BookEntry.COLUMN_UID},
156158
BookEntry.COLUMN_ACTIVE + "= 1", null, null, null, null, "1");
157159
try{
158-
if (cursor.getCount() == 0)
159-
throw new NoActiveBookFoundException("There is no active book in the app. This should NEVER happen, fix your bugs!");
160+
if (cursor.getCount() == 0) {
161+
NoActiveBookFoundException e = new NoActiveBookFoundException(
162+
"There is no active book in the app."
163+
+ "This should NEVER happen, fix your bugs!\n"
164+
+ getNoActiveBookFoundExceptionInfo());
165+
Crashlytics.logException(e);
166+
throw e;
167+
}
160168
cursor.moveToFirst();
161169
return cursor.getString(cursor.getColumnIndexOrThrow(BookEntry.COLUMN_UID));
162170
} finally {
163171
cursor.close();
164172
}
165173
}
166174

175+
private String getNoActiveBookFoundExceptionInfo() {
176+
StringBuilder info = new StringBuilder("UID, created, source\n");
177+
for (Book book : getAllRecords()) {
178+
info.append(String.format("%s, %s, %s\n",
179+
book.getUID(),
180+
book.getCreatedTimestamp(),
181+
book.getSourceUri()));
182+
}
183+
return info.toString();
184+
}
185+
167186
public class NoActiveBookFoundException extends RuntimeException {
168187
public NoActiveBookFoundException(String message) {
169188
super(message);

0 commit comments

Comments
 (0)