Some improvements related to generator error recovery

This commit is contained in:
Simon Binder 2020-07-07 23:01:02 +02:00
parent 6f0fa9cde1
commit 7ff91a620a
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
6 changed files with 30 additions and 9 deletions

View File

@ -34,7 +34,7 @@ class AnalyzeDartStep extends AnalyzingStep {
affectedElement: accessor.fromClass,
message: msg.toString(),
));
} catch (e) {
} on Exception catch (e) {
// unknown error while sorting
reportError(ErrorInDartCode(
severity: Severity.warning,
@ -43,6 +43,9 @@ class AnalyzeDartStep extends AnalyzingStep {
));
}
// Just to have something in case the above breaks.
availableEntities ??= const [];
final availableQueries = transitiveImports
.map((f) => f.currentResult)
.whereType<ParsedMoorFile>()

View File

@ -1,3 +1,4 @@
import 'package:moor_generator/moor_generator.dart' show MoorColumn;
import 'package:sqlparser/sqlparser.dart';
import '../query_handler.dart';
@ -119,10 +120,17 @@ class _LintingVisitor extends RecursiveVisitor<void, void> {
);
// second, check that no required columns are left out
final specifiedTable = linter.mapper.tableToMoor(e.table.resolved as Table);
final required = specifiedTable.columns
.where(specifiedTable.isColumnRequiredForInsert)
.toList();
final resolved = e.table.resolved;
List<MoorColumn> required;
if (resolved is Table) {
final specifiedTable =
linter.mapper.tableToMoor(e.table.resolved as Table);
required = specifiedTable.columns
.where(specifiedTable.isColumnRequiredForInsert)
.toList();
} else {
required = const [];
}
if (required.isNotEmpty && e.source is DefaultValues) {
linter.lints.add(AnalysisError(

View File

@ -9,6 +9,9 @@ abstract class MoorSchemaEntity implements HasDeclaration {
/// For tables, this can be contents of a `REFERENCES` clause. For triggers,
/// it would be the tables watched.
///
/// If an entity contains an (invalid) null reference, that should not be
/// included in [references].
///
/// The generator will verify that the graph of entities and [references]
/// is acyclic and sort them topologically.
Iterable<MoorSchemaEntity> get references;

View File

@ -36,5 +36,10 @@ class MoorIndex extends MoorSchemaEntity {
String get displayName => name;
@override
Iterable<MoorSchemaEntity> get references => [table];
Iterable<MoorSchemaEntity> get references {
if (table == null) {
return const Iterable.empty();
}
return [table];
}
}

View File

@ -356,8 +356,10 @@ class Parser extends ParserBase
as = _consumeIdentifier('Expected a name of the result class').identifier;
}
final colon =
_consume(TokenType.colon, 'Expected a colon (:) followed by a query');
final colon = _consume(
TokenType.colon,
'Expected a colon (:) followed by a query. Imports and CREATE '
'statements must appear before the first query.');
final stmt = _crud();
if (stmt == null) {

View File

@ -499,7 +499,7 @@ class KeywordToken extends Token {
IdentifierToken convertToIdentifier() {
isIdentifier = true;
return IdentifierToken(false, span, synthetic: false);
return IdentifierToken(false, span, synthetic: true);
}
}