Remove redundant error handling from project provider, add a better message for deserialization exceptions
This commit is contained in:
parent
78093ae1be
commit
1d1f848611
3 changed files with 16 additions and 21 deletions
|
@ -85,7 +85,7 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings
|
||||||
}
|
}
|
||||||
catch (JsonException ex)
|
catch (JsonException ex)
|
||||||
{
|
{
|
||||||
return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.UnexpectedExceptionProcessingLaunchSettings, ex.Message));
|
return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.DeserializationExceptionMessage, ex.Message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,30 +13,23 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings
|
||||||
|
|
||||||
public LaunchSettingsApplyResult TryApplySettings(JObject document, JObject model, ref ICommand command)
|
public LaunchSettingsApplyResult TryApplySettings(JObject document, JObject model, ref ICommand command)
|
||||||
{
|
{
|
||||||
try
|
var config = model.ToObject<ProjectLaunchSettingsModel>();
|
||||||
|
|
||||||
|
//For now, ignore everything but the environment variables section
|
||||||
|
|
||||||
|
foreach (var entry in config.EnvironmentVariables)
|
||||||
{
|
{
|
||||||
var config = model.ToObject<ProjectLaunchSettingsModel>();
|
string value = Environment.ExpandEnvironmentVariables(entry.Value);
|
||||||
|
//NOTE: MSBuild variables are not expanded like they are in VS
|
||||||
//For now, ignore everything but the environment variables section
|
command.EnvironmentVariable(entry.Key, value);
|
||||||
|
|
||||||
foreach (var entry in config.EnvironmentVariables)
|
|
||||||
{
|
|
||||||
string value = Environment.ExpandEnvironmentVariables(entry.Value);
|
|
||||||
//NOTE: MSBuild variables are not expanded like they are in VS
|
|
||||||
command.EnvironmentVariable(entry.Key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(config.ApplicationUrl))
|
|
||||||
{
|
|
||||||
command.EnvironmentVariable("ASPNETCORE_URLS", config.ApplicationUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new LaunchSettingsApplyResult(true, null, config.LaunchUrl);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
|
if (!string.IsNullOrEmpty(config.ApplicationUrl))
|
||||||
{
|
{
|
||||||
return new LaunchSettingsApplyResult(false, ex.Message);
|
command.EnvironmentVariable("ASPNETCORE_URLS", config.ApplicationUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new LaunchSettingsApplyResult(true, null, config.LaunchUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ProjectLaunchSettingsModel
|
private class ProjectLaunchSettingsModel
|
||||||
|
|
|
@ -50,5 +50,7 @@ namespace Microsoft.DotNet.Tools.Run
|
||||||
public const string UnexpectedExceptionProcessingLaunchSettings = "An unexpected exception occurred while processing launch settings:\n{0}";
|
public const string UnexpectedExceptionProcessingLaunchSettings = "An unexpected exception occurred while processing launch settings:\n{0}";
|
||||||
|
|
||||||
public const string LaunchProfilesCollectionIsNotAJsonObject = "The 'profiles' property of the launch settings document is not a JSON object.";
|
public const string LaunchProfilesCollectionIsNotAJsonObject = "The 'profiles' property of the launch settings document is not a JSON object.";
|
||||||
|
|
||||||
|
public const string DeserializationExceptionMessage = "An error was encountered when reading launchSettings.json.\n{0}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue