Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 18cb217

Browse files
Remove CompilerOptions.onError and CompilationMessage
Change-Id: Ia4ff435c6653c42fb27aecc46177a10ff8a8e4a2 Reviewed-on: https://dart-review.googlesource.com/c/78201 Auto-Submit: Peter von der Ahé <ahe@google.com> Reviewed-by: Aske Simon Christensen <askesc@google.com>
1 parent 2084c5b commit 18cb217

10 files changed

Lines changed: 24 additions & 146 deletions

pkg/front_end/lib/src/api_prototype/compilation_message.dart

Lines changed: 0 additions & 37 deletions
This file was deleted.

pkg/front_end/lib/src/api_prototype/compiler_options.dart

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import '../fasta/fasta_codes.dart' show FormattedMessage;
1010

1111
import '../fasta/severity.dart' show Severity;
1212

13-
import 'compilation_message.dart' show CompilationMessage;
14-
1513
import 'diagnostic_message.dart' show DiagnosticMessageHandler;
1614

1715
import 'file_system.dart' show FileSystem;
@@ -24,9 +22,6 @@ export '../fasta/severity.dart' show Severity;
2422

2523
export 'diagnostic_message.dart' show DiagnosticMessage;
2624

27-
/// Callback used to report errors encountered during compilation.
28-
typedef void ErrorHandler(CompilationMessage error);
29-
3025
typedef void ProblemHandler(FormattedMessage problem, Severity severity,
3126
List<FormattedMessage> context);
3227

@@ -52,12 +47,6 @@ class CompilerOptions {
5247
/// `lib/libraries.json`.
5348
Uri librariesSpecificationUri;
5449

55-
/// Callback to which compilation errors should be delivered.
56-
///
57-
/// By default, when no callback is provided, the compiler will report
58-
/// messages on the console and will throw when fatal errors are discovered.
59-
ErrorHandler onError;
60-
6150
ProblemHandler onProblem;
6251

6352
DiagnosticMessageHandler onDiagnostic;
@@ -169,8 +158,7 @@ class CompilerOptions {
169158
/// Whether to run extra verification steps to validate that compiled
170159
/// components are well formed.
171160
///
172-
/// Errors are reported via the [onError] callback.
173-
// TODO(sigmund): ensure we don't print errors to stdout (Issue #30056)
161+
/// Errors are reported via the [onDiagnostic] callback.
174162
bool verify = false;
175163

176164
/// Whether to dump generated components in a text format (also mainly for

pkg/front_end/lib/src/api_prototype/front_end.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
library front_end.front_end;
99

1010
export 'compiler_options.dart';
11-
export 'compilation_message.dart';
1211
export 'kernel_generator.dart';
1312
export 'summary_generator.dart';
1413
export 'file_system.dart';

pkg/front_end/lib/src/base/processed_options.dart

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ import 'package:package_config/packages_file.dart' as package_config;
1919

2020
import 'package:package_config/src/packages_impl.dart' show MapPackages;
2121

22-
import 'package:source_span/source_span.dart' show SourceSpan, SourceLocation;
23-
24-
import '../api_prototype/compilation_message.dart' show CompilationMessage;
25-
2622
import '../api_prototype/compiler_options.dart' show CompilerOptions;
2723

2824
import '../api_prototype/file_system.dart'
@@ -216,17 +212,9 @@ class ProcessedOptions {
216212
return;
217213
}
218214

219-
// Deprecated reporting mechanisms
220-
if (_raw.onError != null) {
221-
_raw.onError(new _CompilationMessage(message, severity));
222-
for (LocatedMessage message in context) {
223-
_raw.onError(new _CompilationMessage(message, Severity.context));
224-
}
225-
} else {
226-
command_line_reporting.report(message, severity);
227-
for (LocatedMessage message in context) {
228-
command_line_reporting.report(message, Severity.context);
229-
}
215+
command_line_reporting.report(message, severity);
216+
for (LocatedMessage message in context) {
217+
command_line_reporting.report(message, Severity.context);
230218
}
231219
}
232220

@@ -597,8 +585,8 @@ class ProcessedOptions {
597585
sb.writeln('Inputs: ${inputs}');
598586
sb.writeln('Output: ${output}');
599587

600-
sb.writeln('Was error handler provided: '
601-
'${_raw.onError == null ? "no" : "yes"}');
588+
sb.writeln('Was diagnostic message handler provided: '
589+
'${_raw.onDiagnostic == null ? "no" : "yes"}');
602590

603591
sb.writeln('FileSystem: ${_fileSystem.runtimeType} '
604592
'(provided: ${_raw.fileSystem.runtimeType})');
@@ -667,30 +655,3 @@ class HermeticAccessException extends FileSystemException {
667655
@override
668656
String toString() => message;
669657
}
670-
671-
/// Wraps a [LocatedMessage] to implement the public [CompilationMessage] API.
672-
class _CompilationMessage implements CompilationMessage {
673-
final LocatedMessage _original;
674-
final Severity severity;
675-
676-
String get message => _original.message;
677-
678-
String get tip => _original.tip;
679-
680-
String get code => _original.code.name;
681-
682-
String get analyzerCode => _original.code.analyzerCodes?.first;
683-
684-
SourceSpan get span {
685-
if (_original.charOffset == -1) {
686-
if (_original.uri == null) return null;
687-
return new SourceLocation(0, sourceUrl: _original.uri).pointSpan();
688-
}
689-
return new SourceLocation(_original.charOffset, sourceUrl: _original.uri)
690-
.pointSpan();
691-
}
692-
693-
_CompilationMessage(this._original, this.severity);
694-
695-
String toString() => message;
696-
}

pkg/front_end/test/fasta/reexport_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ const int quot=3;
3030
};
3131
await compileUnit(sources.keys.toList(), sources,
3232
options: new CompilerOptions()
33-
..onError = (e) => throw "${e.severity}: ${e.message}");
33+
..onDiagnostic = (m) => throw m.plainTextFormatted.join("\n"));
3434
});
3535
}

pkg/front_end/test/kernel_generator_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ main() {
4242
..librariesSpecificationUri = invalidCoreLibsSpecUri
4343
..sdkSummary = null
4444
..compileSdk = true // To prevent FE from loading an sdk-summary.
45-
..onError = (e) => errors.add(e);
45+
..onDiagnostic = errors.add;
4646

4747
var component =
4848
await compileScript('main() => print("hi");', options: options);
@@ -55,7 +55,7 @@ main() {
5555
var options = new CompilerOptions()
5656
..sdkSummary =
5757
Uri.parse('org-dartlang-test:///not_existing_summary_file')
58-
..onError = (e) => errors.add(e);
58+
..onDiagnostic = errors.add;
5959

6060
var component =
6161
await compileScript('main() => print("hi");', options: options);
@@ -82,7 +82,7 @@ main() {
8282

8383
test('compiler requires a main method', () async {
8484
var errors = [];
85-
var options = new CompilerOptions()..onError = (e) => errors.add(e);
85+
var options = new CompilerOptions()..onDiagnostic = errors.add;
8686
await compileScript('a() => print("hi");', options: options);
8787
expect(errors.first.message, messageMissingMain.message);
8888
});
@@ -151,15 +151,15 @@ main() {
151151
group('kernelForComponent', () {
152152
test('compiler does not require a main method', () async {
153153
var errors = [];
154-
var options = new CompilerOptions()..onError = (e) => errors.add(e);
154+
var options = new CompilerOptions()..onDiagnostic = errors.add;
155155
await compileUnit(['a.dart'], {'a.dart': 'a() => print("hi");'},
156156
options: options);
157157
expect(errors, isEmpty);
158158
});
159159

160160
test('compiler is not hermetic by default', () async {
161161
var errors = [];
162-
var options = new CompilerOptions()..onError = (e) => errors.add(e);
162+
var options = new CompilerOptions()..onDiagnostic = errors.add;
163163
await compileUnit([
164164
'a.dart'
165165
], {

pkg/front_end/test/mixin_export_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ main() {
1616
};
1717
await compileUnit(sources.keys.toList(), sources,
1818
options: new CompilerOptions()
19-
..onError = (e) => throw '${e.severity}: ${e.message}');
19+
..onDiagnostic = (m) => throw m.plainTextFormatted.join("\n"));
2020
});
2121
}

pkg/front_end/test/src/base/processed_options_test.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class ProcessedOptionsTest {
301301
// .packages file should be ignored.
302302
var raw = new CompilerOptions()
303303
..fileSystem = fileSystem
304-
..onError = (e) => errors.add(e);
304+
..onDiagnostic = errors.add;
305305
var processed = new ProcessedOptions(
306306
options: raw,
307307
inputs: [Uri.parse('org-dartlang-test:///base/location/script.dart')]);
@@ -319,7 +319,7 @@ class ProcessedOptionsTest {
319319
var raw = new CompilerOptions()
320320
..fileSystem = fileSystem
321321
..packagesFileUri = new Uri()
322-
..onError = (e) => errors.add(e);
322+
..onDiagnostic = errors.add;
323323
var processed = new ProcessedOptions(options: raw);
324324
var uriTranslator = await processed.getUriTranslator();
325325
expect(uriTranslator.packages.asMap(), isEmpty);
@@ -334,7 +334,7 @@ class ProcessedOptionsTest {
334334
var errors = [];
335335
var raw = new CompilerOptions()
336336
..fileSystem = fileSystem
337-
..onError = (e) => errors.add(e);
337+
..onDiagnostic = errors.add;
338338
var options = new ProcessedOptions(options: raw);
339339
var result = await options.validateOptions();
340340
expect(errors.single.message, messageMissingInput.message);
@@ -345,7 +345,7 @@ class ProcessedOptionsTest {
345345
var errors = [];
346346
var raw = new CompilerOptions()
347347
..fileSystem = fileSystem
348-
..onError = (e) => errors.add(e);
348+
..onDiagnostic = errors.add;
349349
var options =
350350
new ProcessedOptions(options: raw, inputs: [Uri.parse('foo.dart')]);
351351
var result = await options.validateOptions();
@@ -371,7 +371,7 @@ class ProcessedOptionsTest {
371371
var raw = new CompilerOptions()
372372
..sdkRoot = sdkRoot
373373
..fileSystem = fileSystem
374-
..onError = (e) => errors.add(e);
374+
..onDiagnostic = errors.add;
375375
var options =
376376
new ProcessedOptions(options: raw, inputs: [Uri.parse('foo.dart')]);
377377
var result = await options.validateOptions();
@@ -389,7 +389,7 @@ class ProcessedOptionsTest {
389389
var raw = new CompilerOptions()
390390
..sdkRoot = sdkRoot
391391
..fileSystem = fileSystem
392-
..onError = (e) => errors.add(e);
392+
..onDiagnostic = errors.add;
393393
var options =
394394
new ProcessedOptions(options: raw, inputs: [Uri.parse('foo.dart')]);
395395
expect(await options.validateOptions(), isFalse);
@@ -408,7 +408,7 @@ class ProcessedOptionsTest {
408408
var raw = new CompilerOptions()
409409
..sdkSummary = sdkSummary
410410
..fileSystem = fileSystem
411-
..onError = (e) => errors.add(e);
411+
..onDiagnostic = errors.add;
412412
var options =
413413
new ProcessedOptions(options: raw, inputs: [Uri.parse('foo.dart')]);
414414
var result = await options.validateOptions();
@@ -425,7 +425,7 @@ class ProcessedOptionsTest {
425425
var raw = new CompilerOptions()
426426
..sdkSummary = sdkSummary
427427
..fileSystem = fileSystem
428-
..onError = (e) => errors.add(e);
428+
..onDiagnostic = errors.add;
429429
var options =
430430
new ProcessedOptions(options: raw, inputs: [Uri.parse('foo.dart')]);
431431
expect(await options.validateOptions(), isFalse);
@@ -447,7 +447,7 @@ class ProcessedOptionsTest {
447447
var raw = new CompilerOptions()
448448
..sdkRoot = sdkRoot
449449
..fileSystem = fileSystem
450-
..onError = (e) => errors.add(e);
450+
..onDiagnostic = errors.add;
451451
var options =
452452
new ProcessedOptions(options: raw, inputs: [Uri.parse('foo.dart')]);
453453
var result = await options.validateOptions();
@@ -466,7 +466,7 @@ class ProcessedOptionsTest {
466466
var raw = new CompilerOptions()
467467
..sdkSummary = sdkSummary
468468
..fileSystem = fileSystem
469-
..onError = (e) => errors.add(e);
469+
..onDiagnostic = errors.add;
470470
var options =
471471
new ProcessedOptions(options: raw, inputs: [Uri.parse('foo.dart')]);
472472
expect(await options.validateOptions(), isFalse);

pkg/front_end/test/summary_generator_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ main() {
123123

124124
test('summarization by default is not hermetic', () async {
125125
var errors = [];
126-
var options = new CompilerOptions()..onError = (e) => errors.add(e);
126+
var options = new CompilerOptions()..onDiagnostic = errors.add;
127127
await summarize(['b.dart'], allSources, options: options);
128128
expect(errors, isEmpty);
129129
});

pkg/front_end/tool/example.dart

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)