Skip to content

Commit

Permalink
Suppress scanner errors for non-existent URIs.
Browse files Browse the repository at this point in the history
Fixes #23754.

R=scheglov@google.com

Review URL: https://codereview.chromium.org/1378503003 .
  • Loading branch information
pq committed Oct 6, 2015
1 parent 8c7a94e commit 90e975b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
19 changes: 19 additions & 0 deletions pkg/analysis_server/test/analysis/notification_errors_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ library test.analysis.notification_errors;
import 'package:analysis_server/src/constants.dart';
import 'package:analysis_server/src/domain_analysis.dart';
import 'package:analysis_server/src/protocol.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'package:unittest/unittest.dart';

Expand Down Expand Up @@ -35,6 +36,24 @@ class NotificationErrorsTest extends AbstractAnalysisTest {
server.handlers = [new AnalysisDomainHandler(server),];
}

test_importError() {
createProject();

addTestFile('''
import 'does_not_exist.dart';
''');
return waitForTasksFinished().then((_) {
List<AnalysisError> errors = filesErrors[testFile];
// Verify that we are generating only 1 error for the bad URI.
// https://github.com/dart-lang/sdk/issues/23754
expect(errors, hasLength(1));
AnalysisError error = errors[0];
expect(error.severity, AnalysisErrorSeverity.ERROR);
expect(error.type, AnalysisErrorType.COMPILE_TIME_ERROR);
expect(error.message, startsWith('Target of URI does not exist'));
});
}

test_notInAnalysisRoot() {
createProject();
String otherFile = '/other.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkg/analysis_server/test/analysis/test_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import 'update_content_test.dart' as update_content_test;
*/
main() {
initializeTestEnvironment();
group('search', () {
group('analysis', () {
get_errors_test.main();
get_hover_test.main();
get_navigation_test.main();
Expand Down
6 changes: 4 additions & 2 deletions pkg/analyzer/lib/src/generated/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8773,8 +8773,10 @@ class GetContentTask extends AnalysisTask {
AnalysisEngine.instance.instrumentationService
.logFileRead(source.fullName, _modificationTime, _content);
} catch (exception, stackTrace) {
errors.add(new AnalysisError(
source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [exception]));
if (source.exists()) {
errors.add(new AnalysisError(
source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [exception]));
}
throw new AnalysisException("Could not get contents of $source",
new CaughtException(exception, stackTrace));
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/analyzer/lib/src/task/dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3812,8 +3812,10 @@ class ScanDartTask extends SourceBasedAnalysisTask {
message = exception.toString();
}
}
errorListener.onError(new AnalysisError(
source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [message]));
if (source.exists()) {
errorListener.onError(new AnalysisError(
source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [message]));
}
}
if (target is DartScript) {
DartScript script = target;
Expand Down

0 comments on commit 90e975b

Please sign in to comment.