mirror of https://github.com/AMT-Cheif/drift.git
Report error when tables can't be read
This commit is contained in:
parent
878af3add8
commit
c5d696a9eb
|
@ -11,9 +11,17 @@ class UseMoorParser {
|
|||
Future<Database> parseDatabase(
|
||||
ClassElement element, ConstantReader annotation) async {
|
||||
// the types declared in UseMoor.tables
|
||||
final tableTypes =
|
||||
annotation.peek('tables')?.listValue?.map((obj) => obj.toTypeValue()) ??
|
||||
[];
|
||||
final tablesOrNull =
|
||||
annotation.peek('tables')?.listValue?.map((obj) => obj.toTypeValue());
|
||||
if (tablesOrNull == null) {
|
||||
step.reportError(ErrorInDartCode(
|
||||
message: 'Could not read tables from @UseMoor annotation! \n'
|
||||
'Please make sure that all table classes exist.',
|
||||
affectedElement: element,
|
||||
));
|
||||
}
|
||||
|
||||
final tableTypes = tablesOrNull ?? [];
|
||||
final queryStrings = annotation.peek('queries')?.mapValue ?? {};
|
||||
final includes = annotation
|
||||
.read('include')
|
||||
|
|
|
@ -93,7 +93,17 @@ void main() {
|
|||
@override
|
||||
Set<Column> get primaryKey => {other};
|
||||
}
|
||||
'''
|
||||
''',
|
||||
AssetId.parse('test_lib|lib/invalid_reference.dart'): '''
|
||||
import 'package:moor/moor.dart';
|
||||
|
||||
class Foo extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
}
|
||||
|
||||
@UseMoor(tables: [Foo, DoesNotExist])
|
||||
class Database {}
|
||||
''',
|
||||
});
|
||||
});
|
||||
tearDownAll(() {
|
||||
|
@ -284,4 +294,27 @@ void main() {
|
|||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('reports errors for unknown classes in UseMoor', () async {
|
||||
final session = MoorSession(backend);
|
||||
final uri = Uri.parse('package:test_lib/invalid_reference.dart');
|
||||
final backendTask = backend.startTask(uri);
|
||||
final task = session.startTask(backendTask);
|
||||
await task.runTask();
|
||||
|
||||
final file = session.registerFile(uri);
|
||||
expect(
|
||||
file.errors.errors,
|
||||
contains(
|
||||
isA<ErrorInDartCode>().having(
|
||||
(e) => e.message,
|
||||
'message',
|
||||
allOf(
|
||||
contains('Could not read tables from @UseMoor annotation!'),
|
||||
contains('Please make sure that all table classes exist.'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue