Skip to content

Commit d66f1d0

Browse files
cresviphilasmar
authored andcommitted
Updated deployment setting file not exist check. Updated unit test to use error code instead of message.
1 parent 2af4cb8 commit d66f1d0

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

src/AWS.Deploy.Common/Exceptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public enum DeployToolErrorCode
127127
UnsupportedOptionSettingType = 10010500,
128128
FailedToSaveDeploymentSettings = 10010600,
129129
InvalidWindowsManifestFile = 10010700,
130-
DeploymentConfigurationNotFound = 10010800,
130+
UserDeploymentFileNotFound = 10010800,
131131
}
132132

133133
public class ProjectFileNotFoundException : DeployToolException

src/AWS.Deploy.Orchestration/DeploymentSettingsHandler.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,22 @@ public DeploymentSettingsHandler(IFileManager fileManager, IDirectoryManager dir
5252

5353
public async Task<DeploymentSettings?> ReadSettings(string filePath)
5454
{
55-
try
56-
{
57-
var contents = await _fileManager.ReadAllTextAsync(filePath);
58-
var userDeploymentSettings = JsonConvert.DeserializeObject<DeploymentSettings>(contents);
59-
return userDeploymentSettings;
60-
}
61-
catch (IOException ex)
62-
{
63-
throw new InvalidDeploymentSettingsException(DeployToolErrorCode.DeploymentConfigurationNotFound, $"An error occurred while trying to read the deployment settings file located at {filePath}. Make sure the path you provided exists on your file system, and is readable.", ex);
55+
if (_fileManager.Exists(filePath))
56+
{
57+
try
58+
{
59+
var contents = await _fileManager.ReadAllTextAsync(filePath);
60+
var userDeploymentSettings = JsonConvert.DeserializeObject<DeploymentSettings>(contents);
61+
return userDeploymentSettings;
62+
}
63+
catch (Exception ex)
64+
{
65+
throw new InvalidDeploymentSettingsException(DeployToolErrorCode.FailedToDeserializeUserDeploymentFile, $"An error occurred while trying to deserialize the deployment settings file located at {filePath}.\n {ex.Message}", ex);
66+
}
6467
}
65-
catch (Exception ex)
66-
{
67-
throw new InvalidDeploymentSettingsException(DeployToolErrorCode.FailedToDeserializeUserDeploymentFile, $"An error occurred while trying to deserialize the deployment settings file located at {filePath}.\n {ex.Message}", ex);
68+
else
69+
{
70+
throw new InvalidDeploymentSettingsException(DeployToolErrorCode.UserDeploymentFileNotFound, $"The deployment settings file located at {filePath} doesn't exist.");
6871
}
6972
}
7073

test/AWS.Deploy.CLI.Common.UnitTests/ConfigFileDeployment/DeploymentSettingsHandlerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public async Task ReadSettings_InvalidJson()
259259

260260
// ASSERT
261261
var ex = await Assert.ThrowsAsync<InvalidDeploymentSettingsException>(readAction);
262-
Assert.Contains("An error occurred while trying to deserialize the deployment settings file", ex.Message);
262+
Assert.Equal(DeployToolErrorCode.FailedToDeserializeUserDeploymentFile, ex.ErrorCode);
263263
}
264264

265265
[Fact]
@@ -275,7 +275,7 @@ public async Task ReadSettings_FileNotFound()
275275

276276
// ASSERT
277277
var ex = await Assert.ThrowsAsync<InvalidDeploymentSettingsException>(readAction);
278-
Assert.Contains("An error occurred while trying to read the deployment settings file", ex.Message);
278+
Assert.Equal(DeployToolErrorCode.UserDeploymentFileNotFound, ex.ErrorCode);
279279
}
280280

281281
private object GetOptionSettingValue(Recommendation recommendation, string fullyQualifiedId)

0 commit comments

Comments
 (0)