Skip to content

Commit 26cabb7

Browse files
MichaelRFairhurstcommit-bot@chromium.org
authored andcommitted
[analyzer] Add [SilentException] where previously not reported to users.
New errors *not* changed to silent exceptions: https://dart-review.googlesource.com/c/sdk/+/123328/9/pkg/analyzer/lib/src/dart/sdk/sdk.dart https://dart-review.googlesource.com/c/sdk/+/123328/9/pkg/analysis_server/lib/src/analysis_server_abstract.dart These seem worth keeping. Change-Id: I534b07f6cf50c5b251867b647ed6df96a9134c56 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124586 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
1 parent d355778 commit 26cabb7

File tree

9 files changed

+47
-24
lines changed

9 files changed

+47
-24
lines changed

pkg/analysis_server/lib/src/analysis_server.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,9 @@ class ServerContextManagerCallbacks extends ContextManagerCallbacks {
884884
if (result.contextKey != null) {
885885
message += ' context: ${result.contextKey}';
886886
}
887+
// TODO(39284): should this exception be silent?
887888
AnalysisEngine.instance.instrumentationService.logException(
888-
new CaughtException.wrapInMessage(message, result.exception));
889+
new SilentException.wrapInMessage(message, result.exception));
889890
});
890891
analysisServer.driverMap[folder] = analysisDriver;
891892
return analysisDriver;

pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,9 @@ class LspServerContextManagerCallbacks extends ContextManagerCallbacks {
625625
if (result.contextKey != null) {
626626
message += ' context: ${result.contextKey}';
627627
}
628+
// TODO(39284): should this exception be silent?
628629
AnalysisEngine.instance.instrumentationService.logException(
629-
new CaughtException.wrapInMessage(message, result.exception));
630+
new SilentException.wrapInMessage(message, result.exception));
630631
});
631632
analysisServer.driverMap[folder] = analysisDriver;
632633
return analysisDriver;

pkg/analysis_server/test/context_manager_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,8 +2511,8 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
25112511
driverMap[path] = currentDriver;
25122512
currentDriver.exceptions.listen((ExceptionResult result) {
25132513
AnalysisEngine.instance.instrumentationService.logException(
2514-
new CaughtException.wrapInMessage(
2515-
'Analysis failed: ${result.path}', result.exception));
2514+
new CaughtException.withMessage('Analysis failed: ${result.path}',
2515+
result.exception.exception, result.exception.stackTrace));
25162516
});
25172517
return currentDriver;
25182518
}

pkg/analyzer/lib/exception/exception.dart

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ class CaughtException implements Exception {
6868
CaughtException.withMessage(this.message, this.exception, stackTrace)
6969
: this.stackTrace = stackTrace ?? StackTrace.current;
7070

71-
/**
72-
* Create a [CaughtException] to wrap a prior one, adding a [message].
73-
*/
74-
CaughtException.wrapInMessage(String message, CaughtException exception)
75-
: this.withMessage(message, exception, null);
76-
7771
@override
7872
String toString() {
7973
StringBuffer buffer = new StringBuffer();
@@ -108,3 +102,20 @@ class CaughtException implements Exception {
108102
}
109103
}
110104
}
105+
106+
/**
107+
* A form of [CaughtException] that should be silent to users.
108+
*
109+
* This is still considered an exceptional situation and will be sent to crash
110+
* reporting.
111+
*/
112+
class SilentException extends CaughtException {
113+
SilentException(String message, exception, stackTrace)
114+
: super.withMessage(message, exception, stackTrace);
115+
116+
/**
117+
* Create a [SilentException] to wrap a [CaughtException], adding a [message].
118+
*/
119+
SilentException.wrapInMessage(String message, CaughtException exception)
120+
: this(message, exception, null);
121+
}

pkg/analyzer/lib/src/context/source.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ class SourceFactoryImpl implements SourceFactory {
110110
return _internalResolveUri(null, uri);
111111
}
112112
} catch (exception, stackTrace) {
113+
// TODO(39284): should this exception be silent?
113114
AnalysisEngine.instance.instrumentationService.logException(
114-
new CaughtException.withMessage(
115+
new SilentException(
115116
"Could not resolve URI: $absoluteUri", exception, stackTrace));
116117
}
117118
return null;
@@ -123,8 +124,9 @@ class SourceFactoryImpl implements SourceFactory {
123124
try {
124125
return _internalResolveUri(null, absoluteUri);
125126
} on AnalysisException catch (exception, stackTrace) {
127+
// TODO(39284): should this exception be silent?
126128
AnalysisEngine.instance.instrumentationService.logException(
127-
new CaughtException.withMessage(
129+
new SilentException(
128130
"Could not resolve URI: $absoluteUri", exception, stackTrace));
129131
}
130132
}
@@ -144,8 +146,9 @@ class SourceFactoryImpl implements SourceFactory {
144146
} catch (exception, stackTrace) {
145147
String containingFullName =
146148
containingSource != null ? containingSource.fullName : '<null>';
149+
// TODO(39284): should this exception be silent?
147150
AnalysisEngine.instance.instrumentationService
148-
.logException(new CaughtException.withMessage(
151+
.logException(new SilentException(
149152
"Could not resolve URI ($containedUri) "
150153
"relative to source ($containingFullName)",
151154
exception,

pkg/analyzer/lib/src/dart/ast/ast.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,9 @@ class AssignmentExpressionImpl extends ExpressionImpl
648648
} else {
649649
message = "The right-hand size is null";
650650
}
651+
// TODO(39284): should this exception be silent?
651652
AnalysisEngine.instance.instrumentationService.logException(
652-
new CaughtException(new AnalysisException(message), null),
653+
new SilentException(message, new AnalysisException(message), null),
653654
StackTrace.current);
654655
}
655656
_leftHandSide = _becomeParentOf(leftHandSide);

pkg/analyzer/lib/src/dart/ast/utilities.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,9 +2475,9 @@ class ExceptionHandlingDelegatingAstVisitor<T> extends DelegatingAstVisitor<T> {
24752475
buffer.write(currentNode.runtimeType);
24762476
currentNode = currentNode.parent;
24772477
}
2478+
// TODO(39284): should this exception be silent?
24782479
AnalysisEngine.instance.instrumentationService.logException(
2479-
new CaughtException.withMessage(
2480-
buffer.toString(), exception, stackTrace));
2480+
new SilentException(buffer.toString(), exception, stackTrace));
24812481
}
24822482
}
24832483

@@ -2531,8 +2531,9 @@ class NodeLocator extends UnifyingAstVisitor<void> {
25312531
try {
25322532
node.accept(this);
25332533
} catch (exception, stackTrace) {
2534+
// TODO(39284): should this exception be silent?
25342535
AnalysisEngine.instance.instrumentationService.logException(
2535-
new CaughtException.withMessage(
2536+
new SilentException(
25362537
"Unable to locate element at offset ($_startOffset - $_endOffset)",
25372538
exception,
25382539
stackTrace));
@@ -2571,8 +2572,9 @@ class NodeLocator extends UnifyingAstVisitor<void> {
25712572
} catch (exception, stackTrace) {
25722573
// Ignore the exception and proceed in order to visit the rest of the
25732574
// structure.
2575+
// TODO(39284): should this exception be silent?
25742576
AnalysisEngine.instance.instrumentationService.logException(
2575-
new CaughtException.withMessage(
2577+
new SilentException(
25762578
"Exception caught while traversing an AST structure.",
25772579
exception,
25782580
stackTrace));
@@ -2631,8 +2633,9 @@ class NodeLocator2 extends UnifyingAstVisitor<void> {
26312633
try {
26322634
node.accept(this);
26332635
} catch (exception, stackTrace) {
2636+
// TODO(39284): should this exception be silent?
26342637
AnalysisEngine.instance.instrumentationService.logException(
2635-
new CaughtException.withMessage(
2638+
new SilentException(
26362639
"Unable to locate element at offset ($_startOffset - $_endOffset)",
26372640
exception,
26382641
stackTrace));
@@ -2671,8 +2674,9 @@ class NodeLocator2 extends UnifyingAstVisitor<void> {
26712674
} catch (exception, stackTrace) {
26722675
// Ignore the exception and proceed in order to visit the rest of the
26732676
// structure.
2677+
// TODO(39284): should this exception be silent?
26742678
AnalysisEngine.instance.instrumentationService.logException(
2675-
new CaughtException.withMessage(
2679+
new SilentException(
26762680
"Exception caught while traversing an AST structure.",
26772681
exception,
26782682
stackTrace));

pkg/analyzer/lib/src/dart/sdk/sdk.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,9 @@ class FolderBasedDartSdk extends AbstractDartSdk {
635635
if (resourceProvider is MemoryResourceProvider) {
636636
(resourceProvider as MemoryResourceProvider).writeOn(buffer);
637637
}
638+
// TODO(39284): should this exception be silent?
638639
AnalysisEngine.instance.instrumentationService.logException(
639-
new CaughtException.withMessage(
640-
buffer.toString(), lastException, lastStackTrace));
640+
new SilentException(buffer.toString(), lastException, lastStackTrace));
641641
return new LibraryMap();
642642
}
643643

pkg/analyzer/lib/src/generated/source_io.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,15 @@ class PackageUriResolver extends UriResolver {
339339
pkgDir = pkgDir.getCanonicalFile();
340340
} catch (exception, stackTrace) {
341341
if (!exception.toString().contains("Required key not available")) {
342+
// TODO(39284): should this exception be silent?
342343
AnalysisEngine.instance.instrumentationService.logException(
343-
new CaughtException.withMessage(
344+
new SilentException(
344345
"Canonical failed: $pkgDir", exception, stackTrace));
345346
} else if (_CanLogRequiredKeyIoException) {
346347
_CanLogRequiredKeyIoException = false;
348+
// TODO(39284): should this exception be silent?
347349
AnalysisEngine.instance.instrumentationService.logException(
348-
new CaughtException.withMessage(
350+
new SilentException(
349351
"Canonical failed: $pkgDir", exception, stackTrace));
350352
}
351353
}

0 commit comments

Comments
 (0)