From 2f732202b0b0b52fa79203a093242aaf4059b270 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Sat, 16 Sep 2023 17:35:44 +0200 Subject: [PATCH] Show correct annotation name in tables error --- .../lib/src/analysis/resolver/dart/accessor.dart | 5 ++++- .../analysis/resolver/dart/table_parser_test.dart | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drift_dev/lib/src/analysis/resolver/dart/accessor.dart b/drift_dev/lib/src/analysis/resolver/dart/accessor.dart index a52226cb..1fed02e2 100644 --- a/drift_dev/lib/src/analysis/resolver/dart/accessor.dart +++ b/drift_dev/lib/src/analysis/resolver/dart/accessor.dart @@ -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.', )); } diff --git a/drift_dev/test/analysis/resolver/dart/table_parser_test.dart b/drift_dev/test/analysis/resolver/dart/table_parser_test.dart index 6c26c020..4a810ec1 100644 --- a/drift_dev/test/analysis/resolver/dart/table_parser_test.dart +++ b/drift_dev/test/analysis/resolver/dart/table_parser_test.dart @@ -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.'), + )), + ]), ); });