square/sqlbrite

Figure out why BriteDatabaseTest.badQueryCallsError crashes the process

JakeWharton opened this issue · 3 comments

Figure out why BriteDatabaseTest.badQueryCallsError crashes the process

The SQLiteException is thrown when Query#run is called in RecordingObserver#onNext, but this is not allowed in RxJava2 since it's not a fatal exception, which results in process death.

I don't see any actions to take here, since this particular case is a consumer problem.

Exception is handled correctly when used in operators:

@Test public void badQueryCallsErrorInOperator() {
    TestObserver<Employee> o = db.createQuery(TABLE_EMPLOYEE, "SELECT * FROM missing")
        .mapToOne(Employee.MAPPER)
        .test();

    o.awaitTerminalEvent();
    final List<Throwable> errors = o.errors();
    assertThat(errors).hasSize(1);
    assertThat(errors.get(0).getMessage()).contains("no such table: missing");
  }

Only thing we could do is inform users to use safeSubscribe as described in What's-different-in-2.0#leaving-the-reactive-world

@Test public void badQueryCallsError() {
    db.createQuery(TABLE_EMPLOYEE, "SELECT * FROM missing").safeSubscribe(o);
    o.assertErrorContains("no such table: missing");
  }