@@ -47,6 +47,7 @@ class CommandLineOptions {
47
47
static const applyChangesFlag = 'apply-changes' ;
48
48
static const helpFlag = 'help' ;
49
49
static const ignoreErrorsFlag = 'ignore-errors' ;
50
+ static const ignoreExceptionsFlag = 'ignore-exceptions' ;
50
51
static const previewPortOption = 'preview-port' ;
51
52
static const sdkPathOption = 'sdk-path' ;
52
53
static const skipPubOutdatedFlag = 'skip-pub-outdated' ;
@@ -60,6 +61,8 @@ class CommandLineOptions {
60
61
61
62
final bool ignoreErrors;
62
63
64
+ final bool ignoreExceptions;
65
+
63
66
final int previewPort;
64
67
65
68
final String sdkPath;
@@ -74,6 +77,7 @@ class CommandLineOptions {
74
77
{@required this .applyChanges,
75
78
@required this .directory,
76
79
@required this .ignoreErrors,
80
+ @required this .ignoreExceptions,
77
81
@required this .previewPort,
78
82
@required this .sdkPath,
79
83
@required this .skipPubOutdated,
@@ -238,6 +242,10 @@ class MigrationCli {
238
242
239
243
AnalysisContextCollection _contextCollection;
240
244
245
+ bool _hasExceptions = false ;
246
+
247
+ bool _hasAnalysisErrors = false ;
248
+
241
249
MigrationCli (
242
250
{@required this .binaryName,
243
251
@visibleForTesting this .loggerFactory = _defaultLoggerFactory,
@@ -275,6 +283,10 @@ class MigrationCli {
275
283
return contextCollection.contexts.length > 1 ;
276
284
}
277
285
286
+ @visibleForTesting
287
+ bool get isPreviewServerRunning =>
288
+ _fixCodeProcessor? .isPreviewServerRunnning ?? false ;
289
+
278
290
Context get pathContext => resourceProvider.pathContext;
279
291
280
292
/// Blocks until an interrupt signal (control-C) is received. Tests may
@@ -289,12 +301,10 @@ class MigrationCli {
289
301
ResourceProvider resourceProvider, LineInfo getLineInfo (String path),
290
302
{List <String > included = const < String > [],
291
303
int preferredPort,
292
- bool enablePreview = true ,
293
304
String summaryPath}) {
294
305
return NonNullableFix (listener, resourceProvider, getLineInfo,
295
306
included: included,
296
307
preferredPort: preferredPort,
297
- enablePreview: enablePreview,
298
308
summaryPath: summaryPath);
299
309
}
300
310
@@ -349,6 +359,8 @@ class MigrationCli {
349
359
applyChanges: applyChanges,
350
360
directory: migratePath,
351
361
ignoreErrors: argResults[CommandLineOptions .ignoreErrorsFlag] as bool ,
362
+ ignoreExceptions:
363
+ argResults[CommandLineOptions .ignoreExceptionsFlag] as bool ,
352
364
previewPort: previewPort,
353
365
sdkPath: argResults[CommandLineOptions .sdkPathOption] as String ??
354
366
defaultSdkPathOverride ??
@@ -408,13 +420,12 @@ class MigrationCli {
408
420
await _withProgress (
409
421
'${ansi .emphasized ('Generating migration suggestions' )}' , () async {
410
422
_fixCodeProcessor = _FixCodeProcessor (context, this );
411
- _dartFixListener =
412
- DartFixListener ( DriverProviderImpl (resourceProvider, context));
423
+ _dartFixListener = DartFixListener (
424
+ DriverProviderImpl (resourceProvider, context), _exceptionReported );
413
425
nonNullableFix = createNonNullableFix (
414
426
_dartFixListener, resourceProvider, _fixCodeProcessor.getLineInfo,
415
427
included: [options.directory],
416
428
preferredPort: options.previewPort,
417
- enablePreview: options.webPreview,
418
429
summaryPath: options.summary);
419
430
nonNullableFix.rerunFunction = _rerunFunction;
420
431
_fixCodeProcessor.registerCodeTask (nonNullableFix);
@@ -547,6 +558,7 @@ Use this interactive web view to review, improve, or apply the results.
547
558
logger.stdout (
548
559
'Note: analysis errors will result in erroneous migration suggestions.' );
549
560
561
+ _hasAnalysisErrors = true ;
550
562
if (options.ignoreErrors) {
551
563
logger.stdout ('Continuing with migration suggestions due to the use of '
552
564
'--${CommandLineOptions .ignoreErrorsFlag }.' );
@@ -620,6 +632,43 @@ Use this interactive web view to review, improve, or apply the results.
620
632
}
621
633
}
622
634
635
+ void _exceptionReported (String detail) {
636
+ if (_hasExceptions) return ;
637
+ _hasExceptions = true ;
638
+ if (options.ignoreExceptions) {
639
+ logger.stdout ('''
640
+ Exception(s) occurred during migration. Attempting to perform
641
+ migration anyway due to the use of --${CommandLineOptions .ignoreExceptionsFlag }.
642
+
643
+ To see exception details, re-run without --${CommandLineOptions .ignoreExceptionsFlag }.
644
+ ''' );
645
+ } else {
646
+ exitCode = 1 ;
647
+ if (_hasAnalysisErrors) {
648
+ logger.stderr ('''
649
+ Aborting migration due to an exception. This may be due to a bug in
650
+ the migration tool, or it may be due to errors in the source code
651
+ being migrated. If possible, try to fix errors in the source code and
652
+ re-try migrating. If that doesn't work, consider filing a bug report
653
+ at:
654
+ ''' );
655
+ } else {
656
+ logger.stderr ('''
657
+ Aborting migration due to an exception. This most likely is due to a
658
+ bug in the migration tool. Please consider filing a bug report at:
659
+ ''' );
660
+ }
661
+ logger.stderr ('https://github.com/dart-lang/sdk/issues/new' );
662
+ logger.stderr ('''
663
+ To attempt to perform migration anyway, you may re-run with
664
+ --${CommandLineOptions .ignoreExceptionsFlag }.
665
+
666
+ Exception details:
667
+ ''' );
668
+ logger.stderr (detail);
669
+ }
670
+ }
671
+
623
672
bool _isUriError (AnalysisError error) =>
624
673
error.errorCode == CompileTimeErrorCode .URI_DOES_NOT_EXIST ;
625
674
@@ -697,6 +746,12 @@ Use this interactive web view to review, improve, or apply the results.
697
746
help: 'Attempt to perform null safety analysis even if there are '
698
747
'analysis errors in the project.' ,
699
748
);
749
+ parser.addFlag (CommandLineOptions .ignoreExceptionsFlag,
750
+ defaultsTo: false ,
751
+ negatable: false ,
752
+ help:
753
+ 'Attempt to perform null safety analysis even if exceptions occur.' ,
754
+ hide: hide);
700
755
parser.addOption (CommandLineOptions .previewPortOption,
701
756
help:
702
757
'Run the preview server on the specified port. If not specified, '
@@ -780,6 +835,9 @@ class _FixCodeProcessor extends Object {
780
835
_FixCodeProcessor (this .context, this ._migrationCli)
781
836
: pathsToProcess = _computePathsToProcess (context);
782
837
838
+ bool get isPreviewServerRunnning =>
839
+ nonNullableFixTask? .isPreviewServerRunning ?? false ;
840
+
783
841
LineInfo getLineInfo (String path) =>
784
842
context.currentSession.getFile (path).lineInfo;
785
843
@@ -863,7 +921,10 @@ class _FixCodeProcessor extends Object {
863
921
await _task.processUnit (phase, result);
864
922
});
865
923
}
866
- await _task.finish ();
924
+ var state = await _task.finish ();
925
+ if (_migrationCli.exitCode == null && _migrationCli.options.webPreview) {
926
+ await _task.startPreviewServer (state);
927
+ }
867
928
_progressBar.complete ();
868
929
869
930
return nonNullableFixTask.previewUrls;
0 commit comments