mirror of https://github.com/AMT-Cheif/drift.git
Some improvements related to generator error recovery
This commit is contained in:
parent
6f0fa9cde1
commit
7ff91a620a
|
@ -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>()
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -499,7 +499,7 @@ class KeywordToken extends Token {
|
|||
IdentifierToken convertToIdentifier() {
|
||||
isIdentifier = true;
|
||||
|
||||
return IdentifierToken(false, span, synthetic: false);
|
||||
return IdentifierToken(false, span, synthetic: true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue