Skip to content

Commit

Permalink
(chocolateyGH-122) Remove usage of Write-ChocolateyFailure
Browse files Browse the repository at this point in the history
This moves to throwing or rethrowing exceptions instead of using
Write-ChocolateyFailure. Write-ChocolateyFailure is deprecated and due
to be removed, so remove it from Chocolatey methods.
  • Loading branch information
ferventcoder committed Feb 27, 2015
1 parent a572a3f commit eef497d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ param(
Write-Debug "Running 'Install-ChocolateyDesktopLink' with targetFilePath:`'$targetFilePath`'";

if(!$targetFilePath) {
Write-ChocolateyFailure "Install-ChocolateyDesktopLink" "Missing TargetFilePath input parameter."
throw "Install-ChocolateyDesktopLink" "Missing TargetFilePath input parameter."
return
}

if(!(Test-Path($targetFilePath))) {
Write-ChocolateyFailure "Install-ChocolateyDesktopLink" "TargetPath does not exist, so can't create shortcut."
throw "Install-ChocolateyDesktopLink" "TargetPath does not exist, so can't create shortcut."
return
}

Expand All @@ -58,6 +58,6 @@ param(

}
catch {
Write-ChocolateyFailure "Install-ChocolateyDesktopLink" "There were errors attempting to create shortcut. The error message was '$_'."
throw $_.Exception
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,26 @@ directoy, an icon to be used for the shortcut, along with a description and argu
Write-Debug "Running 'Install-ChocolateyShortcut' with parameters ShortcutFilePath: `'$shortcutFilePath`', TargetPath: `'$targetPath`', WorkingDirectory: `'$workingDirectory`', Arguments: `'$arguments`', IconLocation: `'$iconLocation`', Description: `'$description`'";

if(!$shortcutFilePath) {
Write-ChocolateyFailure "Install-ChocolateyShortcut" "Missing ShortCutFilePath input parameter."
return
throw "Install-ChocolateyShortcut" "Missing ShortCutFilePath input parameter."
}

if(!$targetPath) {
Write-ChocolateyFailure "Install-ChocolateyShortcut" "Missing TargetPath input parameter."
return
throw "Install-ChocolateyShortcut" "Missing TargetPath input parameter."
}

if(!(Test-Path($targetPath))) {
Write-ChocolateyFailure "Install-ChocolateyShortcut" "TargetPath does not exist, so can't create shortcut."
return
throw "Install-ChocolateyShortcut" "TargetPath does not exist, so can't create shortcut."
}

if($iconLocation) {
if(!(Test-Path($iconLocation))) {
Write-ChocolateyFailure "Install-ChocolateyShortcut" "IconLocation does not exist, so can't create shortcut."
return
throw "Install-ChocolateyShortcut" "IconLocation does not exist, so can't create shortcut."
}
}

if($workingDirectory) {
if(!(Test-Path($workingDirectory))) {
Write-ChocolateyFailure "Install-ChocolateyShortcut" "WorkingDirectory does not exist, so can't create shortcut."
return
throw "Install-ChocolateyShortcut" "WorkingDirectory does not exist, so can't create shortcut."
}
}

Expand All @@ -112,6 +107,6 @@ directoy, an icon to be used for the shortcut, along with a description and argu

}
catch {
Write-ChocolateyFailure "Install-ChocolateyShortcut" "There were errors attempting to create shortcut. The error message was '$_'."
throw $_.Exception
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ param(
if($version){
$vnum=$version.PSPath.Substring($version.PSPath.LastIndexOf('\')+1)
if($vnum -as [int] -lt 10) {
Write-ChocolateyFailure $packageName "This installed VS version, $vnum, does not support installing VSIX packages. Version 10 is the minimum acceptable version."
return
throw "This installed VS version, $vnum, does not support installing VSIX packages. Version 10 is the minimum acceptable version."
}
$dir=(get-itemProperty $version.PSPath "InstallDir").InstallDir
$installer = Join-Path $dir "VsixInstaller.exe"
Expand All @@ -108,18 +107,16 @@ param(
Get-ChocolateyWebFile $packageName $download $vsixUrl -checksum $checksum -checksumType $checksumType
}
catch {
Write-ChocolateyFailure $packageName "There were errors attempting to retrieve the vsix from $vsixUrl. The error message was '$_'."
return
throw "There were errors attempting to retrieve the vsix from $vsixUrl. The error message was '$_'."
}
Write-Debug "Installing VSIX using $installer"
$exitCode = Install-Vsix "$installer" "$download"
if($exitCode -gt 0 -and $exitCode -ne 1001) { #1001: Already installed
Write-ChocolateyFailure $packageName "There was an error installing '$packageName'. The exit code returned was $exitCode."
return
throw "There was an error installing '$packageName'. The exit code returned was $exitCode."
}
}
else {
Write-ChocolateyFailure $packageName "Visual Studio is not installed or the specified version is not present."
throw "Visual Studio is not installed or the specified version is not present."
}
}

Expand Down

0 comments on commit eef497d

Please sign in to comment.