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

Side by Side Diff: pkg/front_end/lib/src/base/processed_options.dart

Issue 2979623002: Use messages for (some) public API errors (Closed)
Patch Set: Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:front_end/compilation_error.dart'; 7 import 'package:front_end/compilation_error.dart';
8 import 'package:front_end/compiler_options.dart'; 8 import 'package:front_end/compiler_options.dart';
9 import 'package:front_end/file_system.dart'; 9 import 'package:front_end/file_system.dart';
10 import 'package:front_end/src/base/performace_logger.dart'; 10 import 'package:front_end/src/base/performace_logger.dart';
11 import 'package:front_end/src/fasta/fasta_codes.dart';
11 import 'package:front_end/src/fasta/ticker.dart'; 12 import 'package:front_end/src/fasta/ticker.dart';
12 import 'package:front_end/src/fasta/translate_uri.dart'; 13 import 'package:front_end/src/fasta/translate_uri.dart';
13 import 'package:front_end/src/incremental/byte_store.dart'; 14 import 'package:front_end/src/incremental/byte_store.dart';
14 import 'package:front_end/src/multi_root_file_system.dart'; 15 import 'package:front_end/src/multi_root_file_system.dart';
15 import 'package:kernel/kernel.dart' 16 import 'package:kernel/kernel.dart'
16 show Program, loadProgramFromBytes, CanonicalName; 17 show Program, loadProgramFromBytes, CanonicalName;
17 import 'package:kernel/target/targets.dart'; 18 import 'package:kernel/target/targets.dart';
18 import 'package:kernel/target/vm_fasta.dart'; 19 import 'package:kernel/target/vm_fasta.dart';
19 import 'package:package_config/packages_file.dart' as package_config; 20 import 'package:package_config/packages_file.dart' as package_config;
20 import 'package:source_span/source_span.dart' show SourceSpan; 21 import 'package:source_span/source_span.dart' show SourceSpan;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 /// The logger to report compilation progress. 102 /// The logger to report compilation progress.
102 PerformanceLog get logger { 103 PerformanceLog get logger {
103 return _raw.logger; 104 return _raw.logger;
104 } 105 }
105 106
106 /// The byte storage to get and put serialized data. 107 /// The byte storage to get and put serialized data.
107 ByteStore get byteStore { 108 ByteStore get byteStore {
108 return _raw.byteStore; 109 return _raw.byteStore;
109 } 110 }
110 111
111 // TODO(sigmund): delete. We should use messages with error codes directly 112 // TODO(sigmund): delete. Use reportMessage instead.
112 // instead. 113 void deprecated_reportError(String error) {
Siggi Cherem (dart-lang) 2017/07/11 03:57:13 FYI - I'm following Peter's style here, it is a t
ahe 2017/07/12 13:14:43 Thank you, this is helpful as I'm grepping for tha
Siggi Cherem (dart-lang) 2017/07/12 21:54:59 On 2017/07/12 13:14:43, ahe wrote: > On 2017/07/11
113 void reportError(String message) { 114 _raw.onError(new _CompilationError(error));
114 _raw.onError(new _CompilationError(message));
115 } 115 }
116 116
117 void reportMessage(LocatedMessage message) {
118 _raw.onError(message);
119 }
120
121 void reportMessageNoLocation(Message message) =>
ahe 2017/07/12 13:14:43 reportMessageNoLocation -> reportMessageWithoutLoc
Siggi Cherem (dart-lang) 2017/07/12 21:54:58 Done.
122 reportMessage(message.withLocation(null, -1));
123
117 /// Runs various validations checks on the input options. For instance, 124 /// Runs various validations checks on the input options. For instance,
118 /// if an option is a path to a file, it checks that the file exists. 125 /// if an option is a path to a file, it checks that the file exists.
119 Future<bool> validateOptions() async { 126 Future<bool> validateOptions() async {
120 for (var source in inputs) { 127 for (var source in inputs) {
121 if (source.scheme == 'file' && 128 if (source.scheme == 'file' &&
122 !await fileSystem.entityForUri(source).exists()) { 129 !await fileSystem.entityForUri(source).exists()) {
123 reportError("Entry-point file not found: $source"); 130 reportMessageNoLocation(
131 templateMissingInputFile.withArguments('$source'));
124 return false; 132 return false;
125 } 133 }
126 } 134 }
127 135
128 if (_raw.sdkRoot != null && 136 if (_raw.sdkRoot != null &&
129 !await fileSystem.entityForUri(sdkRoot).exists()) { 137 !await fileSystem.entityForUri(sdkRoot).exists()) {
130 reportError("SDK root directory not found: ${sdkRoot}"); 138 reportMessageNoLocation(templateMissingSdkRoot.withArguments('$sdkRoot'));
131 return false; 139 return false;
132 } 140 }
133 141
134 var summary = sdkSummary; 142 var summary = sdkSummary;
135 if (summary != null && !await fileSystem.entityForUri(summary).exists()) { 143 if (summary != null && !await fileSystem.entityForUri(summary).exists()) {
136 reportError("SDK summary not found: ${summary}"); 144 reportMessageNoLocation(
145 templateMissingSdkSummary.withArguments('$summary'));
137 return false; 146 return false;
138 } 147 }
139 148
140 if (compileSdk && summary != null) { 149 if (compileSdk && summary != null) {
141 reportError( 150 reportMessageNoLocation(messageCombinedCompileSdkAndSummary);
Paul Berry 2017/07/11 16:00:59 IMO there should be a distinction between errors t
Siggi Cherem (dart-lang) 2017/07/11 16:03:47 Good points! I like however having precise messag
142 "The compileSdk and sdkSummary options are mutually exclusive");
143 return false; 151 return false;
144 } 152 }
145 return true; 153 return true;
146 } 154 }
147 155
148 /// Determine whether to generate code for the SDK when compiling a 156 /// Determine whether to generate code for the SDK when compiling a
149 /// whole-program. 157 /// whole-program.
150 bool get compileSdk => _raw.compileSdk; 158 bool get compileSdk => _raw.compileSdk;
151 159
152 FileSystem _fileSystem; 160 FileSystem _fileSystem;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 'Invalid access to $uri: ' 346 'Invalid access to $uri: '
339 'the file is accessed in a modular hermetic build, ' 347 'the file is accessed in a modular hermetic build, '
340 'but it was not explicitly listed as an input.'); 348 'but it was not explicitly listed as an input.');
341 349
342 @override 350 @override
343 String toString() => message; 351 String toString() => message;
344 } 352 }
345 353
346 /// An error that only contains a message and no error location. 354 /// An error that only contains a message and no error location.
347 class _CompilationError implements CompilationError { 355 class _CompilationError implements CompilationError {
348 String get correction => null; 356 String get tip => null;
349 SourceSpan get span => null; 357 SourceSpan get span => null;
350 final String message; 358 final String message;
351 _CompilationError(this.message); 359 _CompilationError(this.message);
352 360
353 String toString() => message; 361 String toString() => message;
354 } 362 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698