Skip to content

Commit 41a7a16

Browse files
enhacement: add better error handling and masking for inputs (#101)
# Pull Request ## Issue Issue #, if available: N/A ## Description Description of changes: - Reported by VBD team that the error message is not clear when invalid yaml or json are passed. - The PAT is not masked when using cached values on a second run. ## License By submitting this pull request, I confirm that my contribution is made under the terms of the projects associated license.
1 parent adb21f4 commit 41a7a16

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/ALZ/Private/Get-ALZConfig.ps1

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,28 @@ function Get-ALZConfig {
1313

1414
# Import the config and transform it to a PowerShell object
1515
$extension = (Get-Item -Path $configFilePath).Extension.ToLower()
16+
$config = $null
1617
if($extension -eq ".yml" -or $extension -eq ".yaml") {
1718
if (!(Get-Module -ListAvailable -Name powershell-Yaml)) {
1819
Write-Host "Installing YAML module"
1920
Install-Module powershell-Yaml -Force
2021
}
21-
$config = [PSCustomObject](Get-Content -Path $configFilePath | ConvertFrom-Yaml)
22+
try {
23+
$config = [PSCustomObject](Get-Content -Path $configFilePath | ConvertFrom-Yaml)
24+
} catch {
25+
$errorMessage = "Failed to parse YAML inputs. Please check the YAML file for errors and try again. $_"
26+
Write-Error $errorMessage
27+
throw $errorMessage
28+
}
29+
2230
} elseif($extension -eq ".json") {
23-
$config = Get-Content -Path $configFilePath | ConvertFrom-Json
31+
try {
32+
$config = [PSCustomObject](Get-Content -Path $configFilePath | ConvertFrom-Json)
33+
} catch {
34+
$errorMessage = "Failed to parse JSON inputs. Please check the JSON file for errors and try again. $_"
35+
Write-Error $errorMessage
36+
throw $errorMessage
37+
}
2438
} else {
2539
throw "The config file must be a json or yaml/yml file"
2640
}

src/ALZ/Private/Request-ConfigurationValue.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ function Request-ConfigurationValue {
3737
Write-InformationColored "$($configName) " -ForegroundColor Yellow -NoNewline -InformationAction Continue
3838
if ($hasDefaultValue) {
3939
$displayDefaultValue = $defaultValue -eq "" ? "''" : $defaultValue
40+
if($configValue.Sensitive -and $defaultValue -ne "") {
41+
$displayDefaultValue = "<sensitive>"
42+
}
4043
Write-InformationColored "(default: ${displayDefaultValue}): " -ForegroundColor Yellow -NoNewline -InformationAction Continue
4144
} else {
4245
Write-InformationColored ": " -NoNewline -InformationAction Continue

0 commit comments

Comments
 (0)