Skip to content

Commit 00aabe2

Browse files
committed
generator - better error if source entity isn't found
1 parent ba6efd6 commit 00aabe2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

generator/lib/src/code_chunks.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,18 @@ class CodeChunks {
435435

436436
static String backlinkRelInfo(ModelEntity entity, ModelBacklink bl) {
437437
final srcEntity = entity.model.findEntityByName(bl.srcEntity);
438+
if (srcEntity == null) {
439+
throw InvalidGenerationSourceError(
440+
'Invalid relation backlink ${entity.name}.${bl.name} '
441+
'- source entity ${bl.srcEntity} not found.');
442+
}
438443

439444
// either of these will be set, based on the source field that matches
440445
ModelRelation? srcRel;
441446
ModelProperty? srcProp;
442447

443448
if (bl.srcField.isEmpty) {
444-
final matchingProps = srcEntity!.properties
449+
final matchingProps = srcEntity.properties
445450
.where((p) => p.isRelation && p.relationTarget == entity.name);
446451
final matchingRels =
447452
srcEntity.relations.where((r) => r.targetId == entity.id);
@@ -457,7 +462,7 @@ class CodeChunks {
457462
srcRel = matchingRels.first;
458463
}
459464
} else {
460-
srcProp = srcEntity!.findPropertyByName(bl.srcField);
465+
srcProp = srcEntity.findPropertyByName(bl.srcField);
461466
if (srcProp == null) {
462467
srcRel =
463468
srcEntity.relations.firstWhereOrNull((r) => r.name == bl.srcField);

0 commit comments

Comments
 (0)