Show correct annotation name in tables error

This commit is contained in:
Simon Binder 2023-09-16 17:35:44 +02:00
parent c3d63c36e7
commit 2f732202b0
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 14 additions and 4 deletions

View File

@ -25,9 +25,12 @@ class DartAccessorResolver
final rawTablesOrNull = annotation.getField('tables')?.toListValue();
if (rawTablesOrNull == null) {
final annotationName =
annotation.type?.nameIfInterfaceType ?? 'DriftDatabase';
reportError(DriftAnalysisError.forDartElement(
element,
'Could not read tables from @DriftDatabase annotation! \n'
'Could not read tables from @$annotationName annotation! \n'
'Please make sure that all table classes exist.',
));
}

View File

@ -111,6 +111,9 @@ void main() {
@DriftDatabase(tables: [Foo, DoesNotExist])
class Database {}
@DriftAccessor(tables: [DoesNotExist])
class Accessor {}
''',
'a|lib/invalid_constraints.dart': '''
import 'package:drift/drift.dart';
@ -283,18 +286,22 @@ void main() {
);
});
test('reports errors for unknown classes in UseMoor', () async {
test('reports errors for unknown classes', () async {
final uri = Uri.parse('package:a/invalid_reference.dart');
final file = await backend.driver.fullyAnalyze(uri);
expect(
file.allErrors,
contains(
containsAll([
isDriftError(allOf(
contains('Could not read tables from @DriftDatabase annotation!'),
contains('Please make sure that all table classes exist.'),
)),
),
isDriftError(allOf(
contains('Could not read tables from @DriftAccessor annotation!'),
contains('Please make sure that all table classes exist.'),
)),
]),
);
});