Skip to content

Commit

Permalink
small error handling and formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jantari committed Mar 18, 2023
1 parent 7e17c81 commit 930fd83
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
12 changes: 10 additions & 2 deletions private/Debug-LongRunningProcess.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,17 @@

Write-Debug "Process $($Process.ID) ('$($Process.ProcessName)'):"
Write-Debug " Session: $($Process.SessionId)"
Write-Debug " CommandLine: $($CimProcessInformation.CommandLine)"
if ($CimProcessInformation.CommandLine) {
Write-Debug " CommandLine: $($CimProcessInformation.CommandLine)"
} else {
Write-Debug " CommandLine: <BLANK / INACCESSIBLE>"
}
Write-Debug " StartTime: $($Process.StartTime.TimeOfDay)"
Write-Debug " Parent Id: $($CimProcessInformation.ParentProcessId)"
if ($CimProcessInformation.ParentProcessId) {
Write-Debug " Parent Id: $($CimProcessInformation.ParentProcessId)"
} else {
Write-Debug " Parent Id: <BLANK / INACCESSIBLE>"
}

if ($Process.Threads.ThreadState -ne 'Wait') {
$AllThreadsWaiting = $false
Expand Down
1 change: 1 addition & 0 deletions private/Expand-LSUpdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)

if ($Package.Installer.ExtractCommand) {
Write-Verbose "Extracting package $($Package.ID) ..."
$extractionProcess = Invoke-PackageCommand -Path $WorkingDirectory -Command $Package.Installer.ExtractCommand -RuntimeLimit $script:LSUClientConfiguration.MaxExtractRuntime
if ($extractionProcess.Err) {
Write-Warning "Extraction of package $($Package.ID) has failed!`r`n"
Expand Down
2 changes: 1 addition & 1 deletion private/Get-WindowsVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

$Versions = [System.Collections.Generic.Dictionary[string, Version]]::new()

$CmdOutput = Invoke-PackageCommand -Path $env:SystemRoot -Executable "${env:SystemRoot}\System32\cmd.exe" -Arguments '/D /C VER'
$CmdOutput = Invoke-PackageCommand -Path $env:SystemRoot -Executable "${env:SystemRoot}\System32\cmd.exe" -Arguments '/D /C VER' -RuntimeLimit ([TimeSpan]::FromMinutes(1))
if (-not $CmdOutput.Err) {
$CmdOutputRegex = [regex]::match($CmdOutput.Info.StandardOutput, '[\d\.]+')
if ($CmdOutputRegex.Success) {
Expand Down
9 changes: 5 additions & 4 deletions private/Invoke-PackageCommand.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,13 @@
Write-Debug "(Current session ID: $( [System.Diagnostics.Process]::GetCurrentProcess().SessionId ), Environment.UserInteractive: $( [System.Environment]::UserInteractive ))"
Write-Warning "Process '$Executable' has been running for $($RunspaceTimer.Elapsed)"

# Get-Process -Id errors when passed an empty array so test it first
if ($ProcessIdList) {
foreach ($ProcessId in $ProcessIdList) {
$Process = Get-Process -Id $ProcessId
Write-Warning "${ProcessId}: '$($Process.ProcessName)' started at $($Process.StartTime.TimeOfDay)"
# Getting and piping all processes at once with ErrorAction Ignore silently skips over any process that has already exited
Get-Process -Id $ProcessIdList -ErrorAction Ignore | ForEach-Object {
Write-Warning "$($_.Id): '$($_.ProcessName)' started at $($_.StartTime.TimeOfDay)"

$ProcessDiagnostics = Debug-LongRunningProcess -Process $Process
$ProcessDiagnostics = Debug-LongRunningProcess -Process $_
if ($ProcessDiagnostics.InteractableWindows) {
Write-Warning "Process has windows open, this can help troubleshoot if it is stuck:"
foreach ($OpenWindow in $ProcessDiagnostics.InteractableWindows) {
Expand Down

1 comment on commit 930fd83

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PSScriptAnalyzer results as of this commit:

  • 2 Information
  • 8 Warning
See details
Location : ./public/Set-LSUClientConfiguration.ps1 [1, 10]
RuleName : PSUseShouldProcessForStateChangingFunctions
Severity : Warning
Message  : Function 'Set-LSUClientConfiguration' has verb that could change system state
           . Therefore, the function has to support 'ShouldProcess'.

Location : ./public/Install-LSUpdate.ps1 [135, 21]
RuleName : PSUseOutputTypeCorrectly
Severity : Information
Message  : The cmdlet 'Install-LSUpdate' returns an object of type 'PackageInstallResult
           ' but this type is not declared in the OutputType attribute.

Location : ./public/Install-LSUpdate.ps1 [172, 21]
RuleName : PSUseOutputTypeCorrectly
Severity : Information
Message  : The cmdlet 'Install-LSUpdate' returns an object of type 'PackageInstallResult
           ' but this type is not declared in the OutputType attribute.

Location : ./private/Resolve-XMLDependencies.ps1 [1, 10]
RuleName : PSUseSingularNouns
Severity : Warning
Message  : The cmdlet 'Resolve-XMLDependencies' uses a plural noun. A singular noun shou
           ld be used instead.

Location : ./private/Compare-Array.ps1 [30, 17]
RuleName : PSReviewUnusedParameter
Severity : Warning
Message  : The parameter 'in' has been declared but not used. 

Location : ./private/Invoke-PackageCommand.ps1 [303, 29]
RuleName : PSAvoidUsingEmptyCatchBlock
Severity : Warning
Message  : Empty catch block is used. Please use Write-Error or throw statements in catc
           h blocks.

Location : ./private/Split-ExecutableAndArguments.ps1 [1, 10]
RuleName : PSUseSingularNouns
Severity : Warning
Message  : The cmdlet 'Split-ExecutableAndArguments' uses a plural noun. A singular noun
            should be used instead.

Location : ./private/Debug-LongRunningProcess.ps1 [44, 13]
RuleName : PSAvoidUsingEmptyCatchBlock
Severity : Warning
Message  : Empty catch block is used. Please use Write-Error or throw statements in catc
           h blocks.

Location : ./private/Debug-LongRunningProcess.ps1 [139, 82]
RuleName : PSReviewUnusedParameter
Severity : Warning
Message  : The parameter 'lParam' has been declared but not used. 

Location : ./private/Set-BIOSUpdateRegistryFlag.ps1 [1, 10]
RuleName : PSUseShouldProcessForStateChangingFunctions
Severity : Warning
Message  : Function 'Set-BIOSUpdateRegistryFlag' has verb that could change system state
           . Therefore, the function has to support 'ShouldProcess'.

Please sign in to comment.