Skip to content

Commit 83cf6d6

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: improve error/warning text when there are analysis errors.
Fixes #44144 Bug: #44144 Change-Id: I54ef9ca8f38335df2082d730ba558fd407a07767 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171643 Commit-Queue: Kathy Walrath <[email protected]> Reviewed-by: Kathy Walrath <[email protected]> Auto-Submit: Paul Berry <[email protected]>
1 parent 0831245 commit 83cf6d6

File tree

3 files changed

+36
-42
lines changed

3 files changed

+36
-42
lines changed

pkg/dartdev/test/commands/migrate_test.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ void main() {
1212
}
1313

1414
void defineMigrateTests() {
15-
final didYouForgetToRunPubGet = contains('Did you forget to run "pub get"?');
15+
final runPubGet = contains('Run `dart pub get`');
16+
final setLowerSdkConstraint = contains('Set the lower SDK constraint');
1617

1718
TestProject p;
1819

@@ -60,14 +61,16 @@ void defineMigrateTests() {
6061
var result = p.runSync('migrate', [p.dirPath]);
6162
expect(result.exitCode, 1);
6263
expect(result.stderr, isEmpty);
63-
expect(result.stdout, didYouForgetToRunPubGet);
64+
expect(result.stdout, runPubGet);
65+
expect(result.stdout, isNot(setLowerSdkConstraint));
6466
});
6567

6668
test('non-pub-related error', () {
6769
p = project(mainSrc: 'var missing = "semicolon"\n');
6870
var result = p.runSync('migrate', [p.dirPath]);
6971
expect(result.exitCode, 1);
7072
expect(result.stderr, isEmpty);
71-
expect(result.stdout, isNot(didYouForgetToRunPubGet));
73+
expect(result.stdout, runPubGet);
74+
expect(result.stdout, setLowerSdkConstraint);
7275
});
7376
}

pkg/nnbd_migration/lib/migration_cli.dart

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -861,35 +861,41 @@ Exception details:
861861
for (AnalysisError error in analysisResult.errors) {
862862
renderer.render(error);
863863
}
864-
865864
logger.stdout('');
866-
logger.stdout('Note: analysis errors will result in erroneous migration '
867-
'suggestions.');
868-
869865
_hasAnalysisErrors = true;
866+
870867
if (options.ignoreErrors) {
868+
logger.stdout('Note: analysis errors will result in erroneous migration '
869+
'suggestions.');
871870
logger.stdout('Continuing with migration suggestions due to the use of '
872871
'--${CommandLineOptions.ignoreErrorsFlag}.');
873872
} else {
874873
// Fail with how to continue.
874+
logger.stdout("The migration tool didn't start, due to analysis errors.");
875875
logger.stdout('');
876876
if (analysisResult.hasImportErrors) {
877-
logger
878-
.stdout('Unresolved URIs found. Did you forget to run "pub get"?');
879-
logger.stdout('');
880-
}
881-
if (analysisResult.allSourcesAlreadyMigrated) {
882877
logger.stdout('''
883-
All files appear to have null safety already enabled. Did you update the
884-
language version prior to running "dart migrate"? If so, you need to un-do this
885-
(and re-run "pub get") prior to performing the migration.
878+
The following steps might fix your problem:
879+
1. Run `dart pub get`.
880+
2. Try running `dart migrate` again.
881+
''');
882+
} else if (analysisResult.allSourcesAlreadyMigrated) {
883+
logger.stdout('''
884+
The following steps might fix your problem:
885+
1. Set the lower SDK constraint (in pubspec.yaml) to a version before 2.12.
886+
2. Run `dart pub get`.
887+
3. Try running `dart migrate` again.
888+
''');
889+
} else {
890+
const ignoreErrors = CommandLineOptions.ignoreErrorsFlag;
891+
logger.stdout('''
892+
We recommend fixing the analysis issues before running `dart migrate`.
893+
Alternatively, you can run `dart migrate --$ignoreErrors`, but you might
894+
get erroneous migration suggestions.
886895
''');
887-
logger.stdout('');
888896
}
889897
logger.stdout(
890-
'Please fix the analysis issues (or, force generation of migration '
891-
'suggestions by re-running with '
892-
'--${CommandLineOptions.ignoreErrorsFlag}).');
898+
'More information: https://dart.dev/go/null-safety-migration');
893899
}
894900
}
895901

pkg/nnbd_migration/test/migration_cli_test.dart

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -745,15 +745,9 @@ int f() => null
745745
output,
746746
contains("error • Expected to find ';' at lib${sep}test.dart:1:12 • "
747747
'(expected_token)'));
748-
expect(
749-
output,
750-
contains(
751-
'analysis errors will result in erroneous migration suggestions'));
752-
expect(output, contains('Please fix the analysis issues'));
753-
expect(
754-
output,
755-
isNot(
756-
contains('All files appear to have null safety already enabled')));
748+
expect(output, contains('erroneous migration suggestions'));
749+
expect(output, contains('We recommend fixing the analysis issues'));
750+
expect(output, isNot(contains('Set the lower SDK constraint')));
757751
}
758752

759753
test_lifecycle_ignore_errors_enable() async {
@@ -1488,17 +1482,10 @@ int f() => null;
14881482
var output = logger.stdoutBuffer.toString();
14891483
expect(output, contains('1 analysis issue found'));
14901484
expect(output, contains('uri_does_not_exist'));
1491-
expect(
1492-
output,
1493-
contains(
1494-
'analysis errors will result in erroneous migration suggestions'));
1495-
expect(output,
1496-
contains('Unresolved URIs found. Did you forget to run "pub get"?'));
1497-
expect(output, contains('Please fix the analysis issues'));
1498-
expect(
1499-
output,
1500-
isNot(
1501-
contains('All files appear to have null safety already enabled')));
1485+
expect(output, isNot(contains('erroneous migration suggestions')));
1486+
expect(output, contains('Run `dart pub get`'));
1487+
expect(output, contains('Try running `dart migrate` again'));
1488+
expect(output, isNot(contains('Set the lower SDK constraint')));
15021489
}
15031490

15041491
test_migrate_path_absolute() {
@@ -1912,9 +1899,7 @@ environment:
19121899
errorOutput,
19131900
contains("A value of type 'Null' can't be returned from function 'f' "
19141901
"because it has a return type of 'int'"));
1915-
expect(errorOutput, contains('''
1916-
All files appear to have null safety already enabled. Did you update the
1917-
language version prior to running "dart migrate"?'''));
1902+
expect(errorOutput, contains('Set the lower SDK constraint'));
19181903
}
19191904

19201905
String _getHelpText({@required bool verbose}) {

0 commit comments

Comments
 (0)