Remove redundant error handling from project provider, add a better message for deserialization exceptions

This commit is contained in:
mlorbetske 2017-06-01 09:38:43 -07:00
parent 78093ae1be
commit 1d1f848611
3 changed files with 16 additions and 21 deletions

View file

@ -85,7 +85,7 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings
}
catch (JsonException ex)
{
return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.UnexpectedExceptionProcessingLaunchSettings, ex.Message));
return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.DeserializationExceptionMessage, ex.Message));
}
}

View file

@ -13,30 +13,23 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings
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>();
//For now, ignore everything but the environment variables section
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);
string value = Environment.ExpandEnvironmentVariables(entry.Value);
//NOTE: MSBuild variables are not expanded like they are in VS
command.EnvironmentVariable(entry.Key, value);
}
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

View file

@ -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 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}";
}
}