Skip to content

Commit 0c2e14d

Browse files
🩹 [Patch]: Enhance error handling and summary reporting in documentation generation
1 parent ffe09c2 commit 0c2e14d

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

ā€Žscripts/helpers/Build-PSModuleDocumentation.ps1ā€Ž

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
$commands = $moduleInfo.ExportedCommands.Values | Where-Object { $_.CommandType -ne 'Alias' }
5454

5555
Write-Host "::group::Build docs - Generating markdown help files for $($commands.Count) commands in [$docsOutputFolder]"
56+
$failedCommands = @()
5657
foreach ($command in $commands) {
5758
try {
5859
Write-Host "$($command.Name)" -NoNewline
@@ -68,8 +69,55 @@
6869
Write-Host " - $($PSStyle.Foreground.Green)āœ“$($PSStyle.Reset)"
6970
} catch {
7071
Write-Host " - $($PSStyle.Foreground.Red)āœ—$($PSStyle.Reset)"
71-
$_
72+
$failedCommands += [PSCustomObject]@{
73+
CommandName = $command.Name
74+
Error = $_
75+
ErrorString = $_.ToString()
76+
}
77+
Write-Error $_
78+
}
79+
}
80+
81+
# If there were failures, generate a summary and fail the task
82+
if ($failedCommands.Count -gt 0) {
83+
Write-Host '::endgroup::'
84+
Write-Host '::group::Build docs - Failed commands summary'
85+
Write-Host "$($PSStyle.Foreground.Red)Failed to generate documentation for $($failedCommands.Count) command(s):$($PSStyle.Reset)"
86+
foreach ($failed in $failedCommands) {
87+
Write-Host " $($PSStyle.Foreground.Red)āœ—$($PSStyle.Reset) $($failed.CommandName)"
88+
Write-Host " Error: $($failed.ErrorString)" -ForegroundColor Red
89+
}
90+
91+
$summaryContent = @"
92+
# :x: Documentation Build Failed
93+
94+
Failed to generate documentation for **$($failedCommands.Count)** command(s) out of **$($commands.Count)** total.
95+
96+
## Failed Commands
97+
98+
| Command | Error |
99+
|---------|-------|
100+
"@
101+
foreach ($failed in $failedCommands) {
102+
# Escape pipe characters in error messages for markdown table
103+
$errorMsg = $failed.ErrorString -replace '\|', '\|' -replace "`r`n", '<br>' -replace "`n", '<br>'
104+
$summaryContent += "`n| ``$($failed.CommandName)`` | $errorMsg |"
72105
}
106+
107+
$summaryContent += @"
108+
109+
110+
## Summary
111+
112+
- :white_check_mark: Successful: **$($commands.Count - $failedCommands.Count)**
113+
- :x: Failed: **$($failedCommands.Count)**
114+
115+
"@
116+
$summaryContent | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
117+
118+
Write-Host '::endgroup::'
119+
Write-Error "Documentation generation failed for $($failedCommands.Count) command(s). See above for details."
120+
exit 1
73121
}
74122

75123
Write-Host '::group::Build docs - Generated files'

0 commit comments

Comments
Ā (0)