Add more data to debug no elements in libraryUnit.units

Change-Id: I66c1283924a9003069cfcd9625cb965cb131188c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201380
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/micro/resolve_file.dart b/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
index 6ce2ccd..8696184 100644
--- a/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
+++ b/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
@@ -447,8 +447,16 @@
         completionPath: path,
         performance: performance,
       );
-      var result =
-          libraryUnit.units!.firstWhere((element) => element.path == path);
+      var result = libraryUnit.units!
+          .firstWhereOrNull((element) => element.path == path);
+      // TODO(scheglov) Fix and remove.
+      if (result == null) {
+        throw StateError('''
+libraryFile.path: ${libraryFile.path}
+path: $path
+units: ${libraryUnit.units!.map((e) => '(${e.uri} = ${e.path})').toList()}
+''');
+      }
       return result;
     });
   }