Skip to content

Commit 26ca2a5

Browse files
🩹 [Patch]: Update Assert-GitHubContext error message to include context type info (#469)
This pull request introduces improvements to error handling and messaging in PowerShell scripts related to GitHub context validation and GraphQL query execution. The changes enhance clarity and provide more detailed error information for debugging purposes. - Fixes #468 ### Improvements to error handling * Enhanced error message formatting in `Assert-GitHubContext.ps1`: Updated the error message to include the context name, type, and required types in a more readable format. This improves clarity when the context authentication type does not match the required types for a command. * Detailed GraphQL error messages in `Invoke-GitHubGraphQLQuery.ps1`: Added a clear header ("GraphQL errors occurred") and moved the full error details to the beginning of the error message. This change makes the error output more structured and easier to interpret. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: MariusStorhaug <[email protected]> Co-authored-by: Marius Storhaug <[email protected]>
1 parent f2b89e4 commit 26ca2a5

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

‎src/functions/private/Auth/Context/Assert-GitHubContext.ps1‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@
5353
}
5454
if ($Context -eq 'Anonymous' -and $AuthType -contains 'Anonymous') { return }
5555
if ($Context.AuthType -in $AuthType) { return }
56+
57+
$errorText = "The context '$($Context.Name)' is of type [$($Context.AuthType)] which does not match the required" +
58+
"types [$($AuthType -join ', ')] for [$command]."
5659
$PSCmdlet.ThrowTerminatingError(
5760
[System.Management.Automation.ErrorRecord]::new(
58-
[System.Exception]::new("The context '$($Context.Name)' does not match the required AuthTypes [$AuthType] for [$command]."),
61+
[System.Exception]::new($errorText),
5962
'InvalidContextAuthType',
6063
[System.Management.Automation.ErrorCategory]::InvalidArgument,
6164
$Context

‎src/functions/public/API/Invoke-GitHubGraphQLQuery.ps1‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,23 @@
6060
$queryLines = $Query -split "`n" | ForEach-Object { $_.Trim() }
6161
foreach ($errorItem in $graphQLResponse.errors) {
6262
$errorMessages += @"
63+
64+
GraphQL errors occurred:
65+
Full Error:
66+
$($errorItem | ConvertTo-Json -Depth 10 | Out-String)
67+
6368
GraphQL Error [$($errorItem.type)]:
6469
Message: $($errorItem.message)
6570
Path: $($errorItem.path -join '/')
6671
Locations:
6772
$($errorItem.locations | ForEach-Object { " - [$($_.line):$($_.column)] - $($queryLines[$_.line - 1])" })
6873
69-
Full Error:
70-
$($errorItem | ConvertTo-Json -Depth 10 | Out-String -Stream)
71-
7274
"@
7375

7476
}
7577
$PSCmdlet.ThrowTerminatingError(
7678
[System.Management.Automation.ErrorRecord]::new(
77-
[System.Exception]::new("GraphQL errors occurred:`n$($errorMessages -join "`n`n")"),
79+
[System.Exception]::new($errorMessages),
7880
'GraphQLError',
7981
[System.Management.Automation.ErrorCategory]::InvalidOperation,
8082
$graphQLResponse

0 commit comments

Comments
 (0)