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

Unified Diff: dart/sdk/lib/_internal/compiler/implementation/compiler.dart

Issue 20742002: Clean up error handling. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added documentation guide lines. Created 7 years, 5 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
Index: dart/sdk/lib/_internal/compiler/implementation/compiler.dart
diff --git a/dart/sdk/lib/_internal/compiler/implementation/compiler.dart b/dart/sdk/lib/_internal/compiler/implementation/compiler.dart
index 47e44e73bf95d64fa429537d0333faa515be4d8d..86f5db8a6694bea5537badd7cf79ad520b404139 100644
--- a/dart/sdk/lib/_internal/compiler/implementation/compiler.dart
+++ b/dart/sdk/lib/_internal/compiler/implementation/compiler.dart
@@ -397,7 +397,7 @@ abstract class Compiler implements DiagnosticListener {
} on SpannableAssertionFailure catch (ex) {
if (!hasCrashed) {
SourceSpan span = spanFromSpannable(ex.node);
- reportDiagnostic(span, ex.message, api.Diagnostic.ERROR);
+ reportError(ex.node, MessageKind.GENERIC, {'text': ex.message});
pleaseReportCrash();
}
hasCrashed = true;
@@ -582,7 +582,7 @@ abstract class Compiler implements DiagnosticListener {
void internalError(String message,
{Node node, Token token, HInstruction instruction,
Element element}) {
- cancel('Internal error: $message',
+ cancel('Internal Error: $message',
node: node, token: token,
instruction: instruction, element: element);
}
@@ -608,23 +608,24 @@ abstract class Compiler implements DiagnosticListener {
HInstruction instruction, Element element}) {
assembledCode = null; // Compilation failed. Make sure that we
// don't return a bogus result.
- SourceSpan span = null;
+ Spannable spannable = null;
if (node != null) {
- span = spanFromNode(node);
+ spannable = node;
} else if (token != null) {
- span = spanFromTokens(token, token);
+ spannable = token;
} else if (instruction != null) {
- span = spanFromHInstruction(instruction);
+ spannable = instruction;
} else if (element != null) {
- span = spanFromElement(element);
+ spannable = element;
} else {
throw 'No error location for error: $reason';
}
- reportDiagnostic(span, reason, api.Diagnostic.ERROR);
+ reportError(spannable, MessageKind.GENERIC, {'text': reason});
throw new CompilerCancelledException(reason);
}
SourceSpan spanFromSpannable(Spannable node, [Uri uri]) {
+ if (node == null) return null;
if (node == CURRENT_ELEMENT_SPANNABLE) {
node = currentElement;
}
@@ -644,14 +645,6 @@ abstract class Compiler implements DiagnosticListener {
}
}
- void reportFatalError(String reason, Element element,
- {Node node, Token token, HInstruction instruction}) {
- withCurrentElement(element, () {
- cancel(reason, node: node, token: token, instruction: instruction,
- element: element);
- });
- }
-
void log(message) {
reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO);
}
@@ -698,7 +691,7 @@ abstract class Compiler implements DiagnosticListener {
library.addToScope(dynamicClass, this);
});
}
- if (uri == new Uri(scheme: 'dart', path: 'dart:mirrors')) {
+ if (uri == new Uri(scheme: 'dart', path: 'mirrors')) {
mirrorSystemClass =
findRequiredElement(library, const SourceString('MirrorSystem'));
} else if (uri == new Uri(scheme: 'dart', path: '_collection-dev')) {
@@ -875,22 +868,33 @@ abstract class Compiler implements DiagnosticListener {
if (main == null) {
if (!analyzeOnly) {
// Allow analyze only of libraries with no main.
- reportFatalError('Could not find $MAIN', mainApp);
+ reportFatalError(
+ mainApp,
+ MessageKind.GENERIC,
+ {'text': 'Error: Could not find "${MAIN.slowToString()}".'});
} else if (!analyzeAll) {
reportFatalError(
- "Could not find $MAIN. "
- "No source will be analyzed. "
- "Use '--analyze-all' to analyze all code in the library.",
- mainApp);
+ mainApp,
+ MessageKind.GENERIC,
+ {'text': 'Error: Could not find "${MAIN.slowToString()}". '
+ 'No source will be analyzed. '
+ 'Use "--analyze-all" to analyze all code in the library.'});
}
} else {
if (!main.isFunction()) {
- reportFatalError('main is not a function', main);
+ reportFatalError(
+ main,
+ MessageKind.GENERIC,
+ {'text': 'Error: "${MAIN.slowToString()}" is not a function.'});
}
FunctionElement mainMethod = main;
FunctionSignature parameters = mainMethod.computeSignature(this);
parameters.forEachParameter((Element parameter) {
- reportFatalError('main cannot have parameters', parameter);
+ reportError(
+ parameter,
+ MessageKind.GENERIC,
+ {'text':
+ 'Error: "${MAIN.slowToString()}" cannot have parameters.'});
});
}
@@ -1136,24 +1140,25 @@ abstract class Compiler implements DiagnosticListener {
}
SourceSpan span = spanFromNode(node);
- reportDiagnostic(span, 'Warning: $message', api.Diagnostic.WARNING);
- }
-
- // TODO(ahe): Remove this method.
- reportError(Node node, var message) {
- SourceSpan span = spanFromNode(node);
- reportDiagnostic(span, 'Error: $message', api.Diagnostic.ERROR);
- throw new CompilerCancelledException(message.toString());
+ reportDiagnostic(span, '$message', api.Diagnostic.WARNING);
}
- // TODO(ahe): Rename to reportError when that method has been removed.
- void reportErrorCode(Spannable node, MessageKind errorCode,
- [Map arguments = const {}]) {
+ void reportError(Spannable node,
+ MessageKind errorCode,
+ [Map arguments = const {}]) {
reportMessage(spanFromSpannable(node),
errorCode.error(arguments),
api.Diagnostic.ERROR);
}
+ void reportFatalError(Spannable node, MessageKind errorCode,
+ [Map arguments = const {}]) {
+ reportError(node, errorCode, arguments);
+ // TODO(ahe): Make this only abort the current method.
+ throw new CompilerCancelledException(
+ 'Error: Cannot continue due to previous error.');
+ }
+
// TODO(ahe): Rename to reportWarning when that method has been removed.
void reportWarningCode(Spannable node, MessageKind errorCode,
[Map arguments = const {}]) {
@@ -1177,9 +1182,8 @@ abstract class Compiler implements DiagnosticListener {
}
void reportInternalError(Spannable node, String message) {
- reportMessage(spanFromSpannable(node),
- MessageKind.GENERIC.error({'text': message}),
- api.Diagnostic.ERROR);
+ reportError(
+ node, MessageKind.GENERIC, {'text': 'Internal Error: $message'});
}
void reportMessage(SourceSpan span, Diagnostic message, api.Diagnostic kind) {

Powered by Google App Engine
This is Rietveld 408576698