Skip to content

Commit

Permalink
Throw Specific Exception Types (#29592)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trenly authored Oct 6, 2021
1 parent a12510e commit c5d7c3c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Tools/SandboxTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ if (-Not $SkipManifestValidation -And -Not [String]::IsNullOrWhiteSpace($Manifes
Write-Host '--> Validating Manifest'

if (-Not (Test-Path -Path $Manifest)) {
throw 'The Manifest does not exist.'
throw [System.IO.DirectoryNotFoundException]::new('The Manifest does not exist.')
}

winget.exe validate $Manifest
switch ($LASTEXITCODE) {
'-1978335191' { throw 'Manifest validation failed.' }
'-1978335191' { throw [System.Activities.ValidationException]::new('Manifest validation failed.')}
'-1978335192' { Start-Sleep -Seconds 5 }
Default { continue }
}
Expand Down Expand Up @@ -138,10 +138,11 @@ foreach ($dependency in $dependencies) {
$WebClient.DownloadFile($dependency.url, $dependency.file)
}
catch {
throw "Error downloading $($dependency.url)."
#Pass the exception as an inner exception
throw [System.Net.WebException]::new("Error downloading $($dependency.url).",$_.Exception)
}
if (-not ($dependency.hash -eq $(Get-FileHash $dependency.file).Hash)) {
throw 'Hashes do not match, try gain.'
throw [System.Activities.VersionMismatchException]::new('Dependency hash does not match the downloaded file')
}
}
}
Expand Down Expand Up @@ -289,4 +290,4 @@ $Script

Write-Host

WindowsSandbox $SandboxTestWsbFile
WindowsSandbox $SandboxTestWsbFile

0 comments on commit c5d7c3c

Please sign in to comment.