Skip to content

Commit

Permalink
Throw error when encountering InvalidStatement
Browse files Browse the repository at this point in the history
Fixes #820
  • Loading branch information
tp committed Apr 2, 2024
1 parent 9967c32 commit 8040e0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions floor/lib/src/adapter/query_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ class QueryAdapter {
} else if (rootNode is DeleteStatement) {
result = await _database.rawDelete(sql, arguments).then(_mapResult);
tableName = rootNode.table.tableName;
} else if (rootNode is InvalidStatement) {
// The underlying error is not contained in the node, so in order to find the root cause one needs to run with the debugger stopping on "all exceptions"
throw Exception('Failed to parse "$sql"');
} else {
throw Exception('Unknown statement type: $rootNode');
}

_notifyIfChanged(tableName, result);
Expand Down
6 changes: 6 additions & 0 deletions floor/test/adapter/query_adapter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ void main() {
expect(actual, throwsStateError);
verify(mockDatabaseExecutor.rawQuery(sql));
});

test('exception because query can not be parsed', () async {
final deleteQueryFuture = underTest.queryNoReturn('DELETE * FROM foo');

expect(deleteQueryFuture, throwsA(isA<Exception>().having((e) => e.toString(), 'message', contains('Failed to parse'))));
});
});

group('query list', () {
Expand Down

0 comments on commit 8040e0f

Please sign in to comment.