Skip to content

Commit

Permalink
Removing 'halt execution' messages and throwing the output or previou…
Browse files Browse the repository at this point in the history
…s exception.

Also adding the MS-Correlation Id to a few exception messages.
  • Loading branch information
jowis41 authored and Daniel Belcher committed Jul 11, 2017
1 parent e83a3e2 commit 6c8bed3
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 72 deletions.
5 changes: 3 additions & 2 deletions StoreBroker/NugetTools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ function Get-NugetPackageDllPath
return $cachedAssemblyPath
}

Write-Log "Unable to acquire a reference to $AssemblyName." -Level Error
throw "Halt Execution"
$output = "Unable to acquire a reference to $AssemblyName."
Write-Log $output -Level Error
throw $output
}
71 changes: 42 additions & 29 deletions StoreBroker/PackageTool.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ function Test-Xml
$msg = $msg -join [Environment]::NewLine

Write-Log $msg -Level Error
throw "Halt Execution"
throw $msg
}
}

Expand Down Expand Up @@ -697,8 +697,9 @@ function Convert-ListingToObject

if ($null -eq $image)
{
Write-Log "Could not find image '$($imageFileName)' in any subdirectory of '$imageContainerPath'." -Level Error
throw "Halt Execution"
$output = "Could not find image '$($imageFileName)' in any subdirectory of '$imageContainerPath'."
Write-Log $output -Level Error
throw $output
}

$destinationInPackage = Join-Path $packageImagePath $image.Name
Expand All @@ -718,8 +719,9 @@ function Convert-ListingToObject
}
else
{
Write-Log "Provided image directory was not found: $imageContainerPath" -Level Error
throw "Halt Execution"
$output = "Provided image directory was not found: $imageContainerPath"
Write-Log $output -Level Error
throw $output
}
}
}
Expand All @@ -741,8 +743,9 @@ function Convert-ListingToObject
}
catch [System.InvalidCastException]
{
Write-Log "Provided .xml file is not a valid .xml document: $xmlFilePath" -Level Error
throw "Halt Execution"
$output = "Provided .xml file is not a valid .xml document: $xmlFilePath"
Write-Log $output -Level Error
throw $output
}
}
}
Expand Down Expand Up @@ -955,8 +958,9 @@ function Convert-InAppProductListingToObject
$image = Get-ChildItem -Recurse -File -Path $imageContainerPath -Include $imageFileName | Select-Object -First 1
if ($null -eq $image)
{
Write-Log "Could not find image '$($imageFileName)' in any subdirectory of '$imageContainerPath'." -Level Error
throw "Halt Execution"
$output = "Could not find image '$($imageFileName)' in any subdirectory of '$imageContainerPath'."
Write-Log $output -Level Error
throw $output
}

$destinationInPackage = Join-Path -Path $packageImagePath -ChildPath $image.Name
Expand All @@ -974,17 +978,19 @@ function Convert-InAppProductListingToObject
}
else
{
Write-Log "Provided image directory was not found: $imageContainerPath" -Level Error
throw "Halt Execution"
$output = "Provided image directory was not found: $imageContainerPath"
Write-Log $output -Level Error
throw $output
}
}

Write-Output @{ "lang" = $language.ToLowerInvariant(); "listing" = $listing }
}
catch [System.InvalidCastException]
{
Write-Log "Provided .xml file is not a valid .xml document: $xmlFilePath" -Level Error
throw "Halt Execution"
$output = "Provided .xml file is not a valid .xml document: $xmlFilePath"
Write-Log $output -Level Error
throw $output
}
}
}
Expand Down Expand Up @@ -2007,9 +2013,10 @@ function Get-SubmissionRequestBody
$out = @()
$out += "'$pathWithRelease' is not a valid directory or cannot be found."
$out += "Check the values of '$script:s_PDPRootPath' and '$script:s_Release' and try again."

Write-Log ($out -join [Environment]::NewLine) -Level Error
throw "Halt Execution"

$newLineOutput = ($out -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
}

Expand Down Expand Up @@ -2121,8 +2128,9 @@ function Get-InAppProductSubmissionRequestBody
$out += "'$pathWithRelease' is not a valid directory or cannot be found."
$out += "Check the values of '$script:s_PDPRootPath' and '$script:s_Release' and try again."

Write-Log ($out -join [Environment]::NewLine) -Level Error
throw "Halt Execution"
$newLineOutput = ($out -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
}

Expand Down Expand Up @@ -2221,7 +2229,7 @@ function Resolve-PackageParameters
$out = "$($param): `"$($ParamMap[$param])`" is not a directory or cannot be found."

Write-Log $out -Level Error
throw "Halt Execution"
throw $out
}
}
}
Expand All @@ -2236,8 +2244,9 @@ function Resolve-PackageParameters
$out += "Only one of '$script:s_PDPRootPath' and '$script:s_ImagesRootPath' was specified."
$out += "If one of these parameters is specified, then both must be specified."

Write-Log ($out -join [Environment]::NewLine) -Level Error
throw "Halt Execution"
$newLineOutput = ($out -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
}

Expand All @@ -2250,8 +2259,9 @@ function Resolve-PackageParameters
$configVal = $ConfigObject.packageParameters.OutPath
if ([System.String]::IsNullOrWhiteSpace($configVal))
{
Write-Log ($out -f $script:s_OutPath) -Level Error
throw "Halt Execution"
$newLineOutput = ($out -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
else
{
Expand All @@ -2273,8 +2283,9 @@ function Resolve-PackageParameters
$configVal = $ConfigObject.packageParameters.OutName
if ([System.String]::IsNullOrWhiteSpace($configVal))
{
Write-Log ($out -f $script:s_OutName) -Level Error
throw "Halt Execution"
$output = ($out -f $script:s_OutName)
Write-Log $output -Level Error
throw $output
}
else
{
Expand Down Expand Up @@ -2340,8 +2351,9 @@ function Resolve-PackageParameters
$out += "`"$path`" is not a file or cannot be found."
$out += "See the `"$script:s_AppxPath`" object in the config file."

Write-Log ($out -join [Environment]::NewLine) -Level Error
throw "Halt Execution"
$newLineOutput = ($out -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
else
{
Expand All @@ -2367,8 +2379,9 @@ function Resolve-PackageParameters
$out += "Could not find a file with a supported extension ($($script:supportedExtensions -join ", ")) using the relative path: '$path'."
$out += "See the `"$script:s_AppxPath`" object in the config file."

Write-Log ($out -join [Environment]::NewLine) -Level Error
throw "Halt Execution"
$newLineOutput = ($out -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion StoreBroker/StoreBroker.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CompanyName = 'Microsoft Corporation'
Copyright = 'Copyright (C) Microsoft Corporation. All rights reserved.'

ModuleVersion = '1.8.2'
ModuleVersion = '1.8.3'
Description = 'Provides command-line access to the Windows Store Submission REST API.'

RootModule = 'StoreIngestionApi'
Expand Down
60 changes: 35 additions & 25 deletions StoreBroker/StoreIngestionApi.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,10 @@ function Get-AccessToken
$output += "when you call Set-StoreBrokerAuthentication."
$output += "To learn more on how to get these values, go to 'Installation and Setup' here:"
$output += " http://aka.ms/StoreBroker"
Write-Log $($output -join [Environment]::NewLine) -Level Error

throw "Halt Execution"

$newLineOutput = ($output -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}

# Get our client id and secret, either from the cached credential or by prompting for them.
Expand All @@ -404,8 +405,9 @@ function Get-AccessToken

if ($null -eq $credential)
{
Write-Log "You must supply valid credentials (client id and secret) to use this module." -Level Error
throw "Halt Execution"
$output = "You must supply valid credentials (client id and secret) to use this module."
Write-Log $output -Level Error
throw $output
}

$clientId = $credential.UserName
Expand Down Expand Up @@ -489,8 +491,9 @@ function Get-AccessToken
$output += "StatusDescription: $($_.Exception.Response.StatusDescription)"
$output += "$($_.ErrorDetails | ConvertFrom-JSON | Out-String)"

Write-Log $($output -join [Environment]::NewLine) -Level Error
throw "Halt Execution"
$newLineOutput = ($output -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
catch [System.Management.Automation.RuntimeException]
{
Expand All @@ -508,8 +511,9 @@ function Get-AccessToken
}
}

Write-Log $($output -join [Environment]::NewLine) -Level Error
throw "Halt Execution"
$newLineOutput = ($output -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
}

Expand Down Expand Up @@ -868,8 +872,9 @@ function Set-SubmissionPackage
}

Set-TelemetryException -Exception $_.Exception -ErrorBucket Set-SubmissionPackage -Properties $telemetryProperties
Write-Log $($output -join [Environment]::NewLine) -Level Error
throw "Halt Execution"
$newLineOutput = ($output -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
catch
{
Expand All @@ -883,8 +888,9 @@ function Set-SubmissionPackage
$output += "$($_.ErrorDetails)"

Set-TelemetryException -Exception $_.Exception -ErrorBucket Set-SubmissionPackage -Properties $telemetryProperties
Write-Log $($output -join [Environment]::NewLine) -Level Error
throw "Halt Execution"
$newLineOutput = ($output -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
finally
{
Expand Down Expand Up @@ -1062,8 +1068,9 @@ function Get-SubmissionPackage
}

Set-TelemetryException -Exception $_.Exception -ErrorBucket Get-SubmissionPackage -Properties $telemetryProperties
Write-Log $($output -join [Environment]::NewLine) -Level Error
throw "Halt Execution"
$newLineOutput = ($output -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
catch
{
Expand All @@ -1077,8 +1084,9 @@ function Get-SubmissionPackage
$output += "$($_.ErrorDetails)"

Set-TelemetryException -Exception $_.Exception -ErrorBucket Get-SubmissionPackage -Properties $telemetryProperties
Write-Log $($output -join [Environment]::NewLine) -Level Error
throw "Halt Execution"
$newLineOutput = ($output -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
finally
{
Expand Down Expand Up @@ -1857,7 +1865,7 @@ function Invoke-SBRestMethod
$correlationId = $result.Headers[$script:headerMSCorrelationId]
if (-not [String]::IsNullOrEmpty($correlationId))
{
Write-Log "$($script:headerMSCorrelationId): $correlationId" -Level Verbose
Write-Log "$($script:headerMSCorrelationId) : $correlationId" -Level Verbose
}

# Record the telemetry for this event.
Expand Down Expand Up @@ -1929,13 +1937,13 @@ function Invoke-SBRestMethod
{
Write-Log $_.Exception.Message -Level Error
Set-TelemetryException -Exception $_.Exception -ErrorBucket $errorBucket -Properties $localTelemetryProperties
throw;
throw $script:headerMSCorrelationId + ' : ' + $correlationId + [Environment]::NewLine + $_.Exception.Message;
}

$output = @()
if (-not [string]::IsNullOrEmpty($statusCode))
{
$output += "$statusCode | $statusDescription"
$output += "$statusCode | $($statusDescription.Trim())"
}

$output += $message
Expand All @@ -1947,11 +1955,11 @@ function Invoke-SBRestMethod
$innerMessageJson = ($innerMessage | ConvertFrom-Json)
if ($innerMessageJson -is [String])
{
$output += $innerMessageJson
$output += $innerMessageJson.Trim()
}
else
{
$output += "$($innerMessageJson.code) : $($innerMessageJson.message)"
$output += "$($innerMessageJson.code) : $($innerMessageJson.message.Trim())"
if ($innerMessageJson.details)
{
$output += "$($innerMessageJson.details | Format-Table | Out-String)"
Expand All @@ -1961,18 +1969,20 @@ function Invoke-SBRestMethod
catch [System.ArgumentException]
{
# Will be thrown if $innerMessage isn't JSON content
$output += $innerMessage
$output += $innerMessage.Trim()
}
}

if (-not [String]::IsNullOrEmpty($correlationId))
{
$output += $script:headerMSCorrelationId + ': ' + $correlationId
Write-Log "$($script:headerMSCorrelationId): $correlationId" -Level Verbose
}

Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties
Write-Log $($output -join [Environment]::NewLine) -Level Error
throw "Halt Execution"
$newLineOutput = ($output -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
}

Expand Down
14 changes: 9 additions & 5 deletions StoreBroker/StoreIngestionApplicationApi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1094,8 +1094,10 @@ function Update-ApplicationSubmission
$output = @()
$output += "The AppId [$($submission.appId)] in the submission content [$SubmissionDataPath] does not match the intended AppId [$AppId]."
$output += "You either entered the wrong AppId at the commandline, or you're referencing the wrong submission content to upload."
Write-Log $($output -join [Environment]::NewLine) -Level Error
throw $($output -join [Environment]::NewLine)

$newLineOutput = ($output -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
}

Expand Down Expand Up @@ -1138,8 +1140,10 @@ function Update-ApplicationSubmission
$output = @()
$output += "We can only modify a submission that is in the '$script:keywordPendingCommit' state."
$output += "The submission that you requested to modify ($SubmissionId) is in '$(submissionToUpdate.status)' state."
Write-Log $($output -join [Environment]::NewLine) -Level Error
throw "Halt Execution"

$newLineOutput = ($output -join [Environment]::NewLine)
Write-Log $newLineOutput -Level Error
throw $newLineOutput
}
}

Expand Down Expand Up @@ -1252,7 +1256,7 @@ function Update-ApplicationSubmission
catch
{
Write-Log $_ -Level Error
throw "Halt Execution"
throw
}
}

Expand Down
Loading

0 comments on commit 6c8bed3

Please sign in to comment.