-
Notifications
You must be signed in to change notification settings - Fork 95
Fix exceptions' swallowing #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -120,24 +120,42 @@ $VersionRegEx="/\d+\.\d+[^/]+/" | |||||
$OverrideNonVersionedFiles = !$SkipNonVersionedFiles | ||||||
|
||||||
function Say($str) { | ||||||
try | ||||||
{ | ||||||
try { | ||||||
Write-Host "dotnet-install: $str" | ||||||
} | ||||||
catch | ||||||
{ | ||||||
catch { | ||||||
# Some platforms cannot utilize Write-Host (Azure Functions, for instance). Fall back to Write-Output | ||||||
Write-Output "dotnet-install: $str" | ||||||
} | ||||||
} | ||||||
|
||||||
function Say-Warning($str) { | ||||||
try { | ||||||
Write-Warning "dotnet-install: $str" | ||||||
} | ||||||
catch { | ||||||
# Some platforms cannot utilize Write-Warning (Azure Functions, for instance). Fall back to Write-Output | ||||||
Write-Output "dotnet-install: Warning: $str" | ||||||
} | ||||||
} | ||||||
|
||||||
# Writes a line with error style settings. | ||||||
# Use this function to show a human-readable comment along with an exception. | ||||||
function Say-Error($str) { | ||||||
try { | ||||||
# Write-Error is quite oververbose for the purpose of the function, let's write one line with error style settings. | ||||||
$Host.UI.WriteErrorLine("dotnet-install: $str") | ||||||
} | ||||||
catch { | ||||||
Write-Output "dotnet-install: Error: $str" | ||||||
} | ||||||
} | ||||||
|
||||||
function Say-Verbose($str) { | ||||||
try | ||||||
{ | ||||||
try { | ||||||
Write-Verbose "dotnet-install: $str" | ||||||
} | ||||||
catch | ||||||
{ | ||||||
catch { | ||||||
# Some platforms cannot utilize Write-Verbose (Azure Functions, for instance). Fall back to Write-Output | ||||||
Write-Output "dotnet-install: $str" | ||||||
} | ||||||
|
@@ -154,7 +172,7 @@ function Invoke-With-Retry([ScriptBlock]$ScriptBlock, [int]$MaxAttempts = 3, [in | |||||
|
||||||
while ($true) { | ||||||
try { | ||||||
return $ScriptBlock.Invoke() | ||||||
return & $ScriptBlock | ||||||
} | ||||||
catch { | ||||||
$Attempts++ | ||||||
|
@@ -268,7 +286,8 @@ function GetHTTPResponse([Uri] $Uri) | |||||
# Default timeout for HttpClient is 100s. For a 50 MB download this assumes 500 KB/s average, any less will time out | ||||||
# 20 minutes allows it to work over much slower connections. | ||||||
$HttpClient.Timeout = New-TimeSpan -Minutes 20 | ||||||
$Response = $HttpClient.GetAsync("${Uri}${FeedCredential}").Result | ||||||
$Task = $HttpClient.GetAsync("${Uri}${FeedCredential}").ConfigureAwait("false"); | ||||||
$Response = $Task.GetAwaiter().GetResult(); | ||||||
if (($Response -eq $null) -or (-not ($Response.IsSuccessStatusCode))) { | ||||||
# The feed credential is potentially sensitive info. Do not log FeedCredential to console output. | ||||||
$ErrorMsg = "Failed to download $Uri." | ||||||
|
@@ -279,7 +298,7 @@ function GetHTTPResponse([Uri] $Uri) | |||||
throw $ErrorMsg | ||||||
} | ||||||
|
||||||
return $Response | ||||||
return $Response | ||||||
} | ||||||
finally { | ||||||
if ($HttpClient -ne $null) { | ||||||
|
@@ -313,7 +332,8 @@ function Get-Latest-Version-Info([string]$AzureFeed, [string]$Channel) { | |||||
$Response = GetHTTPResponse -Uri $VersionFileUrl | ||||||
} | ||||||
catch { | ||||||
throw "Could not resolve version information." | ||||||
Say-Error "Could not resolve version information." | ||||||
throw | ||||||
} | ||||||
$StringContent = $Response.Content.ReadAsStringAsync().Result | ||||||
|
||||||
|
@@ -339,7 +359,8 @@ function Parse-Jsonfile-For-Version([string]$JSonFile) { | |||||
$JSonContent = Get-Content($JSonFile) -Raw | ConvertFrom-Json | Select-Object -expand "sdk" -ErrorAction SilentlyContinue | ||||||
} | ||||||
catch { | ||||||
throw "Json file unreadable: '$JSonFile'" | ||||||
Say-Error "Json file unreadable: '$JSonFile'" | ||||||
throw | ||||||
} | ||||||
if ($JSonContent) { | ||||||
try { | ||||||
|
@@ -352,7 +373,8 @@ function Parse-Jsonfile-For-Version([string]$JSonFile) { | |||||
} | ||||||
} | ||||||
catch { | ||||||
throw "Unable to parse the SDK node in '$JSonFile'" | ||||||
Say-Error "Unable to parse the SDK node in '$JSonFile'" | ||||||
throw | ||||||
} | ||||||
} | ||||||
else { | ||||||
|
@@ -621,7 +643,7 @@ function SafeRemoveFile($Path) { | |||||
} | ||||||
catch | ||||||
{ | ||||||
Say "Failed to remove the temporary file: `"$Path`", remove it manually." | ||||||
Say-Warning "Failed to remove the temporary file: `"$Path`", remove it manually." | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -721,8 +743,7 @@ New-Item -ItemType Directory -Force -Path $InstallRoot | Out-Null | |||||
$installDrive = $((Get-Item $InstallRoot).PSDrive.Name); | ||||||
$diskInfo = Get-PSDrive -Name $installDrive | ||||||
if ($diskInfo.Free / 1MB -le 100) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
Say "There is not enough disk space on drive ${installDrive}:" | ||||||
return | ||||||
throw "There is not enough disk space on drive ${installDrive}:" | ||||||
vlada-shubina marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
$ZipPath = [System.IO.Path]::combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName()) | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.