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

Unified Diff: lib/src/formatter_exception.dart

Issue 2837143003: Don't dump a stack trace on the user if the formatter had bad output. (Closed)
Patch Set: Created 3 years, 8 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 | « lib/src/exceptions.dart ('k') | lib/src/io.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/formatter_exception.dart
diff --git a/lib/src/formatter_exception.dart b/lib/src/formatter_exception.dart
deleted file mode 100644
index 6696aa4f35794ed50dfbf8cc5effd7fd9b9918dc..0000000000000000000000000000000000000000
--- a/lib/src/formatter_exception.dart
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-library dart_style.src.formatter_exception;
-
-import 'package:analyzer/analyzer.dart';
-import 'package:source_span/source_span.dart';
-
-/// Thrown when one or more errors occurs while parsing the code to be
-/// formatted.
-class FormatterException implements Exception {
- /// The [AnalysisError]s that occurred.
- final List<AnalysisError> errors;
-
- /// Creates a new FormatterException with an optional error [message].
- const FormatterException(this.errors);
-
- /// Creates a human-friendly representation of the analysis errors.
- String message({bool color}) {
- var buffer = new StringBuffer();
- buffer.writeln("Could not format because the source could not be parsed:");
-
- // In case we get a huge series of cascaded errors, just show the first few.
- var shownErrors = errors;
- if (errors.length > 10) shownErrors = errors.take(10);
-
- for (var error in shownErrors) {
- var source = error.source.contents.data;
-
- // If the parse error is for something missing from the end of the file,
- // the error position will go past the end of the source. In that case,
- // just pad the source with spaces so we can report it nicely.
- if (error.offset + error.length > source.length) {
- source += " " * (error.offset + error.length - source.length);
- }
-
- var file = new SourceFile(source, url: error.source.fullName);
- var span = file.span(error.offset, error.offset + error.length);
- if (buffer.isNotEmpty) buffer.writeln();
- buffer.write(span.message(error.message, color: color));
- }
-
- if (shownErrors.length != errors.length) {
- buffer.writeln();
- buffer.write("(${errors.length - shownErrors.length} more errors...)");
- }
-
- return buffer.toString();
- }
-
- String toString() => message();
-}
« no previous file with comments | « lib/src/exceptions.dart ('k') | lib/src/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698