@@ -946,6 +946,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
946946 _requestedFiles.remove (path).forEach ((completer) {
947947 completer.completeError (exception, stackTrace);
948948 });
949+ _clearLibraryContextAfterException ();
949950 }
950951 return ;
951952 }
@@ -962,6 +963,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
962963 _requestedLibraries.remove (path).forEach ((completer) {
963964 completer.completeError (exception, stackTrace);
964965 });
966+ _clearLibraryContextAfterException ();
965967 }
966968 return ;
967969 }
@@ -1052,6 +1054,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
10521054 }
10531055 } catch (exception, stackTrace) {
10541056 _reportException (path, exception, stackTrace);
1057+ _clearLibraryContextAfterException ();
10551058 } finally {
10561059 _fileTracker.fileWasAnalyzed (path);
10571060 }
@@ -1077,6 +1080,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
10771080 }
10781081 } catch (exception, stackTrace) {
10791082 _reportException (path, exception, stackTrace);
1083+ _clearLibraryContextAfterException ();
10801084 } finally {
10811085 _fileTracker.fileWasAnalyzed (path);
10821086 }
@@ -1101,6 +1105,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
11011105 _requestedParts.remove (path).forEach ((completer) {
11021106 completer.completeError (exception, stackTrace);
11031107 });
1108+ _clearLibraryContextAfterException ();
11041109 }
11051110 return ;
11061111 }
@@ -1116,6 +1121,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
11161121 _resultController.add (result);
11171122 } catch (exception, stackTrace) {
11181123 _reportException (path, exception, stackTrace);
1124+ _clearLibraryContextAfterException ();
11191125 }
11201126 return ;
11211127 }
@@ -1182,6 +1188,14 @@ class AnalysisDriver implements AnalysisDriverGeneric {
11821188 _scheduler.notify (this );
11831189 }
11841190
1191+ /// There was an exception during a file analysis, we don't know why.
1192+ /// But it might have been caused by an inconsistency of files state, and
1193+ /// the library context state. Reset the library context, and hope that
1194+ /// we will solve the inconsistency while loading / building summaries.
1195+ void _clearLibraryContextAfterException () {
1196+ _libraryContext = null ;
1197+ }
1198+
11851199 /// Return the cached or newly computed analysis result of the file with the
11861200 /// given [path] .
11871201 ///
0 commit comments