Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw error when encountering InvalidStatement #821

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions floor_common/lib/src/adapter/query_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,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_common/test/adapter/query_adapter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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
Loading