[dart fix] Catch exception when parsing pubspecs.

Fixes https://github.com/dart-lang/sdk/issues/56473.

Change-Id: I4b69a74c4d0f129ff25a074104b80c6b75e96e9b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380076
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
diff --git a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart
index d6d25e2..35f9fce 100644
--- a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart
+++ b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart
@@ -922,10 +922,17 @@
       Set<String> usedDevDeps,
       ResourceProvider resourceProvider) async {
     String contents = pubspec.contents.data;
-    YamlNode node = loadYamlNode(contents);
+    YamlNode? node;
+    try {
+      node = loadYamlNode(contents);
+    } catch (_) {
+      // Could not parse the pubspec file.
+      return [];
+    }
+
     if (node is! YamlMap) {
       // The file is empty.
-      node = YamlMap();
+      return [];
     }
 
     var errors = MissingDependencyValidator(node, pubspec, resourceProvider)