Skip to content

Commit

Permalink
[release/6.0] Host error message updates (dotnet#70059)
Browse files Browse the repository at this point in the history
* Update error messages for framework and SDK resolution failure

Partial backport of dotnet#67022

* Update error message for runtime not found

Backport of dotnet#67564
  • Loading branch information
elinor-fung authored Jun 9, 2022
1 parent 6f81e35 commit 90fcb77
Show file tree
Hide file tree
Showing 26 changed files with 413 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void InvalidFileOrCommand_NoSDK_ListsPossibleIssues()
.Execute(fExpectedToFail: true)
.Should().Fail()
.And.HaveStdErrContaining($"The application '{fileName}' does not exist")
.And.HaveStdErrContaining($"It was not possible to find any installed .NET SDKs");
.And.FindAnySdk(false);
}

// Return a non-exisitent path that contains a mix of / and \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,32 @@ public static AndConstraint<CommandResultAssertions> ShouldHaveResolvedFramework
/// <returns>Constraint</returns>
public static AndConstraint<CommandResultAssertions> ShouldHaveResolvedFrameworkOrFailToFind(this CommandResult result, string resolvedFrameworkName, string resolvedFrameworkVersion)
{
if (resolvedFrameworkName == null || resolvedFrameworkVersion == null ||
if (resolvedFrameworkName == null || resolvedFrameworkVersion == null ||
resolvedFrameworkVersion == FrameworkResolutionBase.ResolvedFramework.NotFound)
{
return result.ShouldFailToFindCompatibleFrameworkVersion();
return result.ShouldFailToFindCompatibleFrameworkVersion(resolvedFrameworkName);
}
else
{
return result.ShouldHaveResolvedFramework(resolvedFrameworkName, resolvedFrameworkVersion);
}
}

public static AndConstraint<CommandResultAssertions> DidNotFindCompatibleFrameworkVersion(this CommandResultAssertions assertion)
public static AndConstraint<CommandResultAssertions> DidNotFindCompatibleFrameworkVersion(this CommandResultAssertions assertion, string frameworkName, string requestedVersion)
{
return assertion.HaveStdErrContaining("It was not possible to find any compatible framework version");
var constraint = assertion.HaveStdErrContaining("You must install or update .NET to run this application.");
if (frameworkName is not null)
{
constraint = constraint.And.HaveStdErrContaining($"Framework: '{frameworkName}', {(requestedVersion is null ? "" : $"version '{requestedVersion}'")}");
}

return constraint;
}

public static AndConstraint<CommandResultAssertions> ShouldFailToFindCompatibleFrameworkVersion(this CommandResult result)
public static AndConstraint<CommandResultAssertions> ShouldFailToFindCompatibleFrameworkVersion(this CommandResult result, string frameworkName, string requestedVersion = null)
{
return result.Should().Fail()
.And.DidNotFindCompatibleFrameworkVersion();
.And.DidNotFindCompatibleFrameworkVersion(frameworkName, requestedVersion);
}

public static AndConstraint<CommandResultAssertions> FailedToReconcileFrameworkReference(
Expand Down Expand Up @@ -91,7 +97,7 @@ public static AndConstraint<CommandResultAssertions> ShouldHaveResolvedFramework
}
else if (resolvedVersion == FrameworkResolutionBase.ResolvedFramework.NotFound)
{
return result.ShouldFailToFindCompatibleFrameworkVersion();
return result.ShouldFailToFindCompatibleFrameworkVersion(frameworkName, null);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ public void Precedence(
SettingLocation rollForwardOnNoCandidateFxLocation,
bool passes)
{
string requestedVersion = "5.0.0";
CommandResult result = RunTest(
new TestSettings()
.WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
.WithFramework(MicrosoftNETCoreApp, "5.0.0"))
.WithFramework(MicrosoftNETCoreApp, requestedVersion))
.With(RollForwardSetting(rollForwardLocation, Constants.RollForwardSetting.Major))
.With(RollForwardOnNoCandidateFxSetting(rollForwardOnNoCandidateFxLocation, 0)));

Expand All @@ -114,7 +115,7 @@ public void Precedence(
}
else
{
result.Should().Fail().And.DidNotFindCompatibleFrameworkVersion();
result.ShouldFailToFindCompatibleFrameworkVersion(MicrosoftNETCoreApp, requestedVersion);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.FrameworkResolution
{
public class RollForwardOnNoCandidateFx :
public class RollForwardOnNoCandidateFx :
FrameworkResolutionBase,
IClassFixture<RollForwardOnNoCandidateFx.SharedTestState>
{
Expand Down Expand Up @@ -113,18 +113,19 @@ public void RollForwardToLatestPatch_RollForwardOnNoCandidateFx(int? rollForward
[InlineData(2, false, true)]
public void RollForwardOnMinor_RollForwardOnNoCandidateFx(int? rollForwardOnNoCandidateFx, bool? applyPatches, bool passes)
{
string requestedVersion = "5.0.0";
CommandResult result = RunTestWithOneFramework(
runtimeConfig => runtimeConfig
.WithRollForwardOnNoCandidateFx(rollForwardOnNoCandidateFx)
.WithApplyPatches(applyPatches)
.WithFramework(MicrosoftNETCoreApp, "5.0.0"));
.WithFramework(MicrosoftNETCoreApp, requestedVersion));
if (passes)
{
result.ShouldHaveResolvedFramework(MicrosoftNETCoreApp, "5.1.3");
}
else
{
result.ShouldFailToFindCompatibleFrameworkVersion();
result.ShouldFailToFindCompatibleFrameworkVersion(MicrosoftNETCoreApp, requestedVersion);
}
}

Expand All @@ -140,18 +141,19 @@ public void RollForwardOnMinor_RollForwardOnNoCandidateFx(int? rollForwardOnNoCa
[InlineData(2, false, true)]
public void RollForwardOnMajor_RollForwardOnNoCandidateFx(int? rollForwardOnNoCandidateFx, bool? applyPatches, bool passes)
{
string requestedVersion = "4.1.0";
CommandResult result = RunTestWithOneFramework(
runtimeConfig => runtimeConfig
.WithRollForwardOnNoCandidateFx(rollForwardOnNoCandidateFx)
.WithApplyPatches(applyPatches)
.WithFramework(MicrosoftNETCoreApp, "4.1.0"));
.WithFramework(MicrosoftNETCoreApp, requestedVersion));
if (passes)
{
result.ShouldHaveResolvedFramework(MicrosoftNETCoreApp, "5.1.3");
}
else
{
result.ShouldFailToFindCompatibleFrameworkVersion();
result.ShouldFailToFindCompatibleFrameworkVersion(MicrosoftNETCoreApp, requestedVersion);
}
}

Expand All @@ -165,12 +167,13 @@ public void RollForwardOnMajor_RollForwardOnNoCandidateFx(int? rollForwardOnNoCa
[InlineData(2, false)]
public void NeverRollBackOnRelease(int? rollForwardOnNoCandidateFx, bool? applyPatches)
{
string requestedVersion = "5.1.4";
RunTestWithOneFramework(
runtimeConfig => runtimeConfig
.WithRollForwardOnNoCandidateFx(rollForwardOnNoCandidateFx)
.WithApplyPatches(applyPatches)
.WithFramework(MicrosoftNETCoreApp, "5.1.4"))
.ShouldFailToFindCompatibleFrameworkVersion();
.WithFramework(MicrosoftNETCoreApp, requestedVersion))
.ShouldFailToFindCompatibleFrameworkVersion(MicrosoftNETCoreApp, requestedVersion);
}

// Verifies that if both rollForwardOnNoCandidateFx=0 and applyPatches=0 there will be no rolling forward.
Expand Down Expand Up @@ -203,14 +206,14 @@ public void RollForwardDisabledOnCandidateFxAndDisabledApplyPatches_MatchesExact
[Fact]
public void RollForwardOnMinorDisabledOnNoCandidateFx_FailsToRoll()
{
string requestedVersion = "5.0.0";
RunTestWithOneFramework(
runtimeConfig => runtimeConfig
.WithRollForwardOnNoCandidateFx(0)
.WithFramework(MicrosoftNETCoreApp, "5.0.0"))
.WithFramework(MicrosoftNETCoreApp, requestedVersion))
// Will still attempt roll forward to latest patch
.Should().Fail()
.And.HaveStdErrContaining("Attempting FX roll forward")
.And.DidNotFindCompatibleFrameworkVersion();
.ShouldFailToFindCompatibleFrameworkVersion(MicrosoftNETCoreApp, requestedVersion)
.And.HaveStdErrContaining("Attempting FX roll forward");
}

// 3.0 change: In 2.* pre-release never rolled to release. In 3.* it will follow normal roll-forward rules.
Expand Down Expand Up @@ -313,22 +316,23 @@ public void RollForwardToPreReleaseLatestPatch_RollForwardOnNoCandidateFx(int? r
[InlineData(2, null, true)]
[InlineData(2, false, true)]
public void RollForwardToPreReleaseOnMinor_RollForwardOnNoCandidateFx(
int? rollForwardOnNoCandidateFx,
bool? applyPatches,
int? rollForwardOnNoCandidateFx,
bool? applyPatches,
bool passes)
{
string requestedVersion = "5.0.0";
CommandResult result = RunTestWithPreReleaseFramework(
runtimeConfig => runtimeConfig
.WithRollForwardOnNoCandidateFx(rollForwardOnNoCandidateFx)
.WithApplyPatches(applyPatches)
.WithFramework(MicrosoftNETCoreApp, "5.0.0"));
.WithFramework(MicrosoftNETCoreApp, requestedVersion));
if (passes)
{
result.ShouldHaveResolvedFramework(MicrosoftNETCoreApp, "5.1.3-preview.2");
}
else
{
result.ShouldFailToFindCompatibleFrameworkVersion();
result.ShouldFailToFindCompatibleFrameworkVersion(MicrosoftNETCoreApp, requestedVersion);
}
}

Expand All @@ -346,18 +350,19 @@ public void RollForwardToPreReleaseOnMajor_RollForwardOnNoCandidateFx(
bool? applyPatches,
bool passes)
{
string requestedVersion = "4.1.0";
CommandResult result = RunTestWithPreReleaseFramework(
runtimeConfig => runtimeConfig
.WithRollForwardOnNoCandidateFx(rollForwardOnNoCandidateFx)
.WithApplyPatches(applyPatches)
.WithFramework(MicrosoftNETCoreApp, "4.1.0"));
.WithFramework(MicrosoftNETCoreApp, requestedVersion));
if (passes)
{
result.ShouldHaveResolvedFramework(MicrosoftNETCoreApp, "5.1.3-preview.2");
}
else
{
result.ShouldFailToFindCompatibleFrameworkVersion();
result.ShouldFailToFindCompatibleFrameworkVersion(MicrosoftNETCoreApp, requestedVersion);
}
}

Expand All @@ -371,12 +376,13 @@ public void RollForwardToPreReleaseOnMajor_RollForwardOnNoCandidateFx(
[InlineData(2, false)]
public void NeverRollBackOnPreRelease(int? rollForwardOnNoCandidateFx, bool? applyPatches)
{
string requestedVersion = "5.1.3-preview.9";
RunTestWithPreReleaseFramework(
runtimeConfig => runtimeConfig
.WithRollForwardOnNoCandidateFx(rollForwardOnNoCandidateFx)
.WithApplyPatches(applyPatches)
.WithFramework(MicrosoftNETCoreApp, "5.1.3-preview.9"))
.ShouldFailToFindCompatibleFrameworkVersion();
.WithFramework(MicrosoftNETCoreApp, requestedVersion))
.ShouldFailToFindCompatibleFrameworkVersion(MicrosoftNETCoreApp, requestedVersion);
}

private CommandResult RunTestWithPreReleaseFramework(Func<RuntimeConfig, RuntimeConfig> runtimeConfig)
Expand Down Expand Up @@ -623,7 +629,7 @@ public void RollForwardToPreReleaseToClosestPreRelease_FromRelease(
[InlineData(2, false, "2.3.2")] // Pre-release is ignored, roll forward to closest release available
public void RollForwardToClosestReleaseWithPreReleaseAvailable_FromRelease(
int? rollForwardOnNoCandidateFx,
bool? applyPatches,
bool? applyPatches,
string resolvedFramework)
{
RunTestWithManyVersions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public RollForwardOnNoCandidateFxSettings(SharedTestState sharedState)
[Fact]
public void Default()
{
string requestedVersion = "4.0.0";
RunTest(
new TestSettings()
.WithRuntimeConfigCustomizer(runtimeConfig => runtimeConfig
.WithFramework(MicrosoftNETCoreApp, "4.0.0")))
.Should().Fail()
.And.DidNotFindCompatibleFrameworkVersion();
.WithFramework(MicrosoftNETCoreApp, requestedVersion)))
.ShouldFailToFindCompatibleFrameworkVersion(MicrosoftNETCoreApp, requestedVersion);

RunTest(
new TestSettings()
Expand Down Expand Up @@ -122,7 +122,7 @@ public void EnvironmentPriority(SettingLocation settingLocation, bool envVariabl
// Verifies interaction between variour <settingLocation> and inner framework reference setting
[Theory] // settingLocation innerReferenceWins
// Command line overrides everything - even inner framework references
[InlineData(SettingLocation.CommandLine, false)]
[InlineData(SettingLocation.CommandLine, false)]
[InlineData(SettingLocation.RuntimeOptions, true)]
[InlineData(SettingLocation.FrameworkReference, true)]
[InlineData(SettingLocation.Environment, true)]
Expand All @@ -149,7 +149,7 @@ public void InnerFrameworkReference(SettingLocation settingLocation, bool innerR
// RuntimeOptions and FrameworkReference settings are not inherited to inner reference
[InlineData(SettingLocation.FrameworkReference, false)]
// Since none is specified for the inner reference, environment is used
[InlineData(SettingLocation.Environment, true)]
[InlineData(SettingLocation.Environment, true)]
public void NoInheritance_MoreRelaxed(SettingLocation settingLocation, bool appWins)
{
RunTest(
Expand All @@ -172,7 +172,7 @@ public void NoInheritance_MoreRelaxed(SettingLocation settingLocation, bool appW
// RuntimeOptions and FrameworkReference settings are not inherited to inner reference
[InlineData(SettingLocation.FrameworkReference, false)]
// Since none is specified for the inner reference, environment is used
[InlineData(SettingLocation.Environment, true)]
[InlineData(SettingLocation.Environment, true)]
public void NoInheritance_MoreRestrictive(SettingLocation settingLocation, bool appWins)
{
RunTest(
Expand All @@ -186,7 +186,7 @@ public void NoInheritance_MoreRestrictive(SettingLocation settingLocation, bool
.ShouldHaveResolvedFrameworkOrFailToFind(MicrosoftNETCoreApp, appWins ? null : "5.1.3");
}

private CommandResult RunTest(TestSettings testSettings) =>
private CommandResult RunTest(TestSettings testSettings) =>
RunTest(SharedState.DotNetWithFrameworks, SharedState.FrameworkReferenceApp, testSettings);

public class SharedTestState : SharedTestStateBase
Expand All @@ -202,7 +202,7 @@ public SharedTestState()
.AddMicrosoftNETCoreAppFrameworkMockHostPolicy("2.5.5")
.AddMicrosoftNETCoreAppFrameworkMockHostPolicy("5.1.3")
.AddFramework(
MiddleWare, "2.1.2",
MiddleWare, "2.1.2",
runtimeConfig => runtimeConfig.WithFramework(MicrosoftNETCoreApp, "5.1.3"))
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ public void RollForwardOnMajor_FromReleaseToPreRelease(string rollForward, bool?
[InlineData(Constants.RollForwardSetting.LatestPatch, false)]
public void NeverRollBackOnPreRelease_PreReleaseOnly(string rollForward, bool? applyPatches)
{
string requestedVersion = "5.1.2-preview.3";
RunTest(
"5.1.2-preview.3",
requestedVersion,
rollForward,
applyPatches)
.ShouldFailToFindCompatibleFrameworkVersion();
.ShouldFailToFindCompatibleFrameworkVersion(MicrosoftNETCoreApp, requestedVersion);
}

// Verifies that rollForward settings won't roll back (on patch).
Expand All @@ -139,11 +140,12 @@ public void NeverRollBackOnPreRelease_PreReleaseOnly(string rollForward, bool? a
[InlineData(Constants.RollForwardSetting.LatestPatch, false)]
public void NeverRollBackOnPatch_PreReleaseOnly(string rollForward, bool? applyPatches)
{
string requestedVersion = "5.1.3-preview.1";
RunTest(
"5.1.3-preview.1",
requestedVersion,
rollForward,
applyPatches)
.ShouldFailToFindCompatibleFrameworkVersion();
.ShouldFailToFindCompatibleFrameworkVersion(MicrosoftNETCoreApp, requestedVersion);
}

// Verifies that rollForward settings won't roll back (on minor).
Expand All @@ -157,11 +159,12 @@ public void NeverRollBackOnPatch_PreReleaseOnly(string rollForward, bool? applyP
[InlineData(Constants.RollForwardSetting.LatestMinor, false)]
public void NeverRollBackOnMinor_PreReleaseOnly(string rollForward, bool? applyPatches)
{
string requestedVersion = "5.3.0-preview.1";
RunTest(
"5.3.0-preview.1",
requestedVersion,
rollForward,
applyPatches)
.ShouldFailToFindCompatibleFrameworkVersion();
.ShouldFailToFindCompatibleFrameworkVersion(MicrosoftNETCoreApp, requestedVersion);
}

// Verifies that rollForward settings won't roll back (on major).
Expand All @@ -175,11 +178,12 @@ public void NeverRollBackOnMinor_PreReleaseOnly(string rollForward, bool? applyP
[InlineData(Constants.RollForwardSetting.LatestMinor, false)]
public void NeverRollBackOnMajor_PreReleaseOnly(string rollForward, bool? applyPatches)
{
string requestedVersion = "7.1.0-preview.1";
RunTest(
"7.1.0-preview.1",
requestedVersion,
rollForward,
applyPatches)
.ShouldFailToFindCompatibleFrameworkVersion();
.ShouldFailToFindCompatibleFrameworkVersion(MicrosoftNETCoreApp, requestedVersion);
}

// Verifies that rollForward settings behave as expected starting with framework reference
Expand Down
Loading

0 comments on commit 90fcb77

Please sign in to comment.