Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Unified Diff: pkg/analysis_server/lib/src/services/correction/util.dart

Issue 2391173003: Catch and suppress expected exceptions in corrections. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/correction/util.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/util.dart b/pkg/analysis_server/lib/src/services/correction/util.dart
index 8a357d696ba12a1b04d5334ba2f7bda3418cd9f6..82f2652821af8769cecb3c758646fdaba19e5446 100644
--- a/pkg/analysis_server/lib/src/services/correction/util.dart
+++ b/pkg/analysis_server/lib/src/services/correction/util.dart
@@ -31,14 +31,19 @@ import 'package:path/path.dart';
*/
void addLibraryImports(SourceChange change, LibraryElement targetLibrary,
Set<LibraryElement> libraries) {
- CompilationUnitElement libUnitElement = targetLibrary.definingCompilationUnit;
- CompilationUnit libUnit = getParsedUnit(libUnitElement);
- CorrectionUtils libUtils = new CorrectionUtils(libUnit);
+ CorrectionUtils libUtils;
+ try {
+ CompilationUnitElement unitElement = targetLibrary.definingCompilationUnit;
+ CompilationUnit unitAst = getParsedUnit(unitElement);
+ libUtils = new CorrectionUtils(unitAst);
+ } catch (e) {
+ throw new CancelCorrectionException(exception: e);
+ }
String eol = libUtils.endOfLine;
// Prepare information about existing imports.
LibraryDirective libraryDirective;
List<_ImportDirectiveInfo> importDirectives = <_ImportDirectiveInfo>[];
- for (Directive directive in libUnit.directives) {
+ for (Directive directive in libUtils.unit.directives) {
if (directive is LibraryDirective) {
libraryDirective = directive;
} else if (directive is ImportDirective) {
@@ -664,6 +669,17 @@ Expression stepUpNamedExpression(Expression expression) {
}
/**
+ * This exception is thrown to cancel the current correction operation,
+ * such as quick assist or quick fix because an inconsistency was detected.
+ * These inconsistencies may happen as a part of normal workflow, e.g. because
+ * a resource was deleted, or an analysis result was invalidated.
+ */
+class CancelCorrectionException {
+ final Object exception;
+ CancelCorrectionException({this.exception});
+}
+
+/**
* Describes the location for a newly created [ClassMember].
*/
class ClassMemberLocation {
@@ -689,8 +705,12 @@ class CorrectionUtils {
CorrectionUtils(this.unit) {
CompilationUnitElement unitElement = unit.element;
+ AnalysisContext context = unitElement.context;
+ if (context == null) {
+ throw new CancelCorrectionException();
Brian Wilkerson 2016/10/05 13:52:20 How often does this occur? Should we log the issue
+ }
this._library = unitElement.library;
- this._buffer = unitElement.context.getContents(unitElement.source).data;
+ this._buffer = context.getContents(unitElement.source).data;
}
/**
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698