-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Request
Problem: Several private functions that use GraphQL to fetch a single resource do not check for $null before constructing class instances. When the queried resource does not exist (e.g., a deleted repository, a non-existent enterprise, or a release with no matching tag), the GraphQL response returns null for that field, causing constructor errors.
Context
With the introduction of partial error handling in Invoke-GitHubGraphQLQuery (see #557), GraphQL queries can now return partial data where some fields are null alongside errors. Functions must guard against null values to avoid runtime exceptions when constructing typed objects.
Acceptance criteria
- All affected functions check for null before calling class constructors
- Functions silently return nothing (no output) when the queried resource is null
- No constructor errors when querying non-existent repositories, enterprises, or releases
Technical decisions
Pattern: Assign the GraphQL result to a variable, then wrap the constructor call in an if ($variable) check. This is consistent with PowerShell idioms and keeps the code readable.
Affected functions:
| Function | File | Null field |
|---|---|---|
Get-GitHubRepositoryByName |
src/functions/private/Repositories/Get-GitHubRepositoryByName.ps1 |
$_.repositoryOwner.repository |
Get-GitHubMyRepositoryByName |
src/functions/private/Repositories/Get-GitHubMyRepositoryByName.ps1 |
$_.viewer.repository |
Get-GitHubEnterpriseByName |
src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 |
$enterpriseResult.enterprise |
Get-GitHubReleaseAssetByTag |
src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByTag.ps1 |
$_.repository.release |
Get-GitHubReleaseAssetFromLatest |
src/functions/private/Releases/Assets/Get-GitHubReleaseAssetFromLatest.ps1 |
$_.repository.latestRelease |
No new tests: These are defensive null checks on private functions. They will be exercised by existing integration tests when querying non-existent resources.
Implementation plan
Core changes
-
Get-GitHubRepositoryByName— guard$_.repositoryOwner.repositorybefore constructing[GitHubRepository] -
Get-GitHubMyRepositoryByName— guard$_.viewer.repositorybefore constructing[GitHubRepository] -
Get-GitHubEnterpriseByName— guard$enterpriseResult.enterprisebefore constructing[GitHubEnterprise] -
Get-GitHubReleaseAssetByTag— guard$_.repository.releasebefore processing assets and pagination -
Get-GitHubReleaseAssetFromLatest— guard$_.repository.latestReleasebefore processing assets and pagination
Metadata
Metadata
Assignees
Labels
Type
Projects
Status