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

Unified Diff: lib/src/formatter.dart

Issue 2061383003: Fix NSME when file contents cannot be read (#260). (Closed) Base URL: https://github.com/dart-lang/linter.git@master
Patch Set: better_handling Created 4 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/formatter.dart
diff --git a/lib/src/formatter.dart b/lib/src/formatter.dart
index 0c091c2e83e423c4856ecfe23798fc9eacab5563..77d28895ac20833dc45a097eb0c3a998636e2023 100644
--- a/lib/src/formatter.dart
+++ b/lib/src/formatter.dart
@@ -14,16 +14,21 @@ import 'package:analyzer/src/services/lint.dart';
import 'package:linter/src/linter.dart';
String getLineContents(int lineNumber, AnalysisError error) {
- var path = error.source.fullName;
- var file = new File(path);
- if (file.existsSync()) {
+ String path = error.source.fullName;
+ File file = new File(path);
+ String failureDetails;
+ if (!file.existsSync()) {
+ failureDetails = 'file at $path does not exist';
+ } else {
var lines = file.readAsLinesSync();
var lineIndex = lineNumber - 1;
if (lines.length > lineIndex) {
return lines[lineIndex];
}
+ failureDetails =
+ 'line index ($lineIndex), outside of file line range (${lines.length})';
}
- return null;
+ throw new StateError('Unable to get contents for line: $failureDetails');
}
String pluralize(String word, int count) =>
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698