Open chilversc opened 4 years ago
Looks like https://github.com/GoogleCloudPlatform/google-cloud-powershell/blob/b0549f98b2a150830ff6ddf10c66c3252df7626d/Google.PowerShell/Compute/GceMetadataCmdlet.cs#L161 is missing a call to response.EnsureSuccessCode()
before accessing response.Content
.
When using the
Get-GceMetadata
cmdlet it doesn't seem to write errors to the error stream or throw exceptions when the metadata server returns an error such as 404.Currently there doesn't seem to be a reasonable way to detect that there was an error.
Steps to reproduce
Expected result
Test 1 should output a blank result and the console should show the error text (normally in red). Test 2 shouldn't show any output as script should halt
Actual result
The error response is stored in
$Result
. When writing the result to the console it dumps a large block of HTML that contains a description of the error (e.g. 404).Workarounds
Invoke-RestMethod
Get-GceInstance
Many of the properties you need from the metadata are available directly from the instance object model. However, obtaining a specific metadata attribute by name can be a awkward.