Add null checks to prevent premature script exit in GCP sizing#107
Open
visharma28 wants to merge 1 commit into
Open
Add null checks to prevent premature script exit in GCP sizing#107visharma28 wants to merge 1 commit into
visharma28 wants to merge 1 commit into
Conversation
…n GCP sizing script - Add null check for \ to skip instance processing when API calls fail - Add try-catch wrapper around entire instance processing loop to handle null reference errors - Add try-catch blocks around individual disk retrieval operations with graceful error handling - Add null check for \ to skip failed disk operations - Add null check for \ to skip disk processing when API calls fail - Fix bug where \.Status should be \.Status (line 333) This prevents the script from crashing when encountering API errors, permission issues, or null disk sources, allowing it to continue processing other projects and instances.
11 tasks
bhaskard
reviewed
Nov 14, 2025
| Write-Progress -ID 2 -Activity "Processing GCE VM Instance: $($instance.Name)" -Status "Project: $($instanceCounter) of $($instanceInfo.Count)" -PercentComplete (($instanceCounter / $instanceInfo.Count) * 100) | ||
| $instanceCounter++ | ||
| # Skip processing if instanceInfo is null (due to API failure) | ||
| if ($instanceInfo -eq $null) { |
Contributor
There was a problem hiding this comment.
NIT: if ($null -eq $instanceInfo)
bhaskard
reviewed
Nov 14, 2025
| continue | ||
| } | ||
|
|
||
| if ($diskInfo -eq $null) { |
Contributor
There was a problem hiding this comment.
NIT: if ($null -eq $diskInfo)
bhaskard
approved these changes
Nov 14, 2025
Member
|
This has merge conflicts with master. Could you rebase and resolve? Happy to review once updated. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
This PR adds comprehensive null checks and error handling to the GCP sizing PowerShell script to prevent premature script termination when encountering API errors, permission issues, or null values during instance and disk processing.
What?
$instanceInfoto skip instance processing whenGet-GceInstanceAPI call failsGet-GceDisk) with proper error handling and continue statements$diskInfoafter disk retrieval to skip failed disk operations$allDisksto skip unattached disk processing whenGet-GceDiskAPI call fails$vm.Statuswas incorrectly used instead of$instance.StatusWhy?
$disk.Sourcevalues or API failures$vm.Statusinstead of$instance.Statuscaused incorrect status reporting in the output CSVHow?
if ($variable -eq $null)checks before processing$instanceInfoand$allDiskscollections to prevent iteration over null objectsGet-GceDiskcalls withcontinuestatements to skip failed disk retrievals without stopping the loop$diskInfoafter retrieval attempts, logging warnings and usingcontinueto skip to next disk$vm.Statuswith correct$instance.Statusto access the instance object's Status propertyTest Plan:
[System.Management.Automation.Language.Parser]::ParseFile()spark-dev-100that has Compute Engine API disabled - script logged "No instance information available" and continued without crashing$instanceInfogracefully by skipping instance processing and logging appropriate warning message$allDisksgracefully by skipping unattached disk processing and logging appropriate warning messagecontinuestatement without terminating the script$instance.Statusinstead of undefined$vm.Statushttps://phabricator.rubrik.com/P19812
JIRA Issues:
SIZENG-48
Revert Plan: