mirror of https://github.com/AMT-Cheif/drift.git
Improve error messages when the preparing builder fails
This commit is contained in:
parent
f5996cb957
commit
43f90b6a43
|
@ -210,10 +210,21 @@ class CreateTableReader {
|
|||
Future<UsedTypeConverter> _readTypeConverter(
|
||||
ColumnType sqlType, MappedBy mapper) async {
|
||||
final code = mapper.mapper.dartCode;
|
||||
final type = await step.task.backend.resolveTypeOf(step.file.uri, code);
|
||||
|
||||
// todo report lint for any of those cases or when resolveTypeOf throws
|
||||
DartType type;
|
||||
try {
|
||||
type = await step.task.backend.resolveTypeOf(step.file.uri, code);
|
||||
} on CannotLoadTypeException catch (e) {
|
||||
step.reportError(ErrorInMoorFile(span: mapper.span, message: e.msg));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (type is! InterfaceType) {
|
||||
step.reportError(
|
||||
ErrorInMoorFile(
|
||||
span: mapper.span,
|
||||
message: 'Must be an interface type (backed by a class)'),
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ abstract class BackendTask {
|
|||
Future<String> readMoor(Uri uri);
|
||||
|
||||
Future<DartType> resolveTypeOf(Uri context, String dartExpression) {
|
||||
throw UnsupportedError('Resolving dart expressions not supported');
|
||||
throw CannotLoadTypeException('Resolving dart expressions not supported');
|
||||
}
|
||||
|
||||
Future<AstNode> loadElementDeclaration(Element element) async {
|
||||
|
@ -59,3 +59,9 @@ class NotALibraryException implements Exception {
|
|||
|
||||
NotALibraryException(this.uri);
|
||||
}
|
||||
|
||||
class CannotLoadTypeException implements Exception {
|
||||
final String msg;
|
||||
|
||||
CannotLoadTypeException(this.msg);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,8 @@ class BuildBackendTask extends BackendTask {
|
|||
_resolve(context).changeExtension('.dart_in_moor');
|
||||
|
||||
if (!await step.canRead(preparedHelperFile)) {
|
||||
throw AssetNotFoundException(preparedHelperFile);
|
||||
throw CannotLoadTypeException('Generated helper file not found. '
|
||||
'Check the build log for earlier errors.');
|
||||
}
|
||||
|
||||
final content = await step.readAsString(preparedHelperFile);
|
||||
|
|
|
@ -41,7 +41,7 @@ dependencies:
|
|||
dev_dependencies:
|
||||
test: ^1.6.0
|
||||
build_runner: ^1.6.7
|
||||
build_test: ^0.10.10
|
||||
build_test: ^1.3.4
|
||||
json_serializable: ^4.0.0-nullsafety
|
||||
|
||||
executables:
|
||||
|
|
Loading…
Reference in New Issue