From 8040e0f8b6d322d4b9888fdc8d632dd788e8b31e Mon Sep 17 00:00:00 2001 From: Timm Preetz <timm@preetz.us> Date: Tue, 2 Apr 2024 14:50:49 +0200 Subject: [PATCH] Throw error when encountering `InvalidStatement` Fixes #820 --- floor/lib/src/adapter/query_adapter.dart | 5 +++++ floor/test/adapter/query_adapter_test.dart | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/floor/lib/src/adapter/query_adapter.dart b/floor/lib/src/adapter/query_adapter.dart index 8169c3a7..dede1af6 100644 --- a/floor/lib/src/adapter/query_adapter.dart +++ b/floor/lib/src/adapter/query_adapter.dart @@ -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); diff --git a/floor/test/adapter/query_adapter_test.dart b/floor/test/adapter/query_adapter_test.dart index 063bf93b..e831f796 100644 --- a/floor/test/adapter/query_adapter_test.dart +++ b/floor/test/adapter/query_adapter_test.dart @@ -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', () {