Skip to content

Commit

Permalink
Suppress caught errors in Invoke-FromScheduledTask from bubbling up t…
Browse files Browse the repository at this point in the history
…o final result
  • Loading branch information
mwrock committed Jan 18, 2015
1 parent 0d24896 commit 0f23c44
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
28 changes: 17 additions & 11 deletions BoxStarter.Common/Invoke-FromTask.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ Remove-BoxstarterTask

if($taskProc -ne $null){
write-debug "Command launched in process $taskProc"
$waitProc=get-process -id $taskProc -ErrorAction SilentlyContinue
Write-Debug "Waiting on $($waitProc.Id)"
try {
$waitProc=get-process -id $taskProc -ErrorAction Stop
Write-Debug "Waiting on $($waitProc.Id)"
} catch { $global:error.RemoveAt(0) }
}

Wait-ForTask $waitProc $idleTimeout $totalTimeout
Expand All @@ -69,20 +71,20 @@ function Get-ChildProcessMemoryUsage {
[int]$res=0
Get-WmiObject -Class Win32_Process -Filter "ParentProcessID=$ID" | % {
if($_.ProcessID -ne $null) {
$proc = Get-Process -ID $_.ProcessID -ErrorAction SilentlyContinue
if($proc -ne $null){
try {
$proc = Get-Process -ID $_.ProcessID -ErrorAction Stop
$res += $proc.PrivateMemorySize + $proc.WorkingSet
Write-Debug "$($_.Name) $($proc.PrivateMemorySize + $proc.WorkingSet)"
}
} catch { $global:error.RemoveAt(0) }
}
}
Get-WmiObject -Class Win32_Process -Filter "ParentProcessID=$ID" | % {
if($_.ProcessID -ne $null) {
$proc = Get-Process -ID $_.ProcessID -ErrorAction SilentlyContinue
if($proc -ne $null){
try {
$proc = Get-Process -ID $_.ProcessID -ErrorAction Top
$res += Get-ChildProcessMemoryUsage $_.ProcessID;
Write-Debug "$($_.Name) $($proc.PrivateMemorySize + $proc.WorkingSet)"
}
} catch { $global:error.RemoveAt(0) }
}
}
$res
Expand Down Expand Up @@ -193,10 +195,14 @@ function Wait-ForTask($waitProc, $idleTimeout, $totalTimeout){
function KillTree($id){
Get-WmiObject -Class Win32_Process -Filter "ParentProcessID=$ID" | % {
if($_.ProcessID -ne $null) {
kill $_.ProcessID -ErrorAction SilentlyContinue -Force
Invoke-SilentKill $_.ProcessID
Write-Debug "Killing $($_.Name)"
KillTree $_.ProcessID
}
}
Kill $id -ErrorAction SilentlyContinue -Force
}
Invoke-SilentKill $id
}

function Invoke-SilentKill($id) {
try {Kill $id -ErrorAction Stop -Force } catch { $global:error.RemoveAt(0) }
}
1 change: 1 addition & 0 deletions BuildScripts/releaseNotes.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<releaseNotes>
- Suppress caught errors in Invoke-FromScheduledTask from bubbling up to final result
- Work around nuget.exe limitations of handling files in system profile directory
- Provide improved error logging of chocolatey errors.
- Fixes issue where windows update reboots maching in the midst of a run.
Expand Down

0 comments on commit 0f23c44

Please sign in to comment.