@@ -92,22 +92,51 @@ function Update-MDSection {
9292
9393 # The new content to insert between the section markers.
9494 [Parameter ()]
95- [string ] $Content
95+ [string ] $Content ,
96+
97+ # Skip update when the target file or section markers are missing.
98+ [Parameter ()]
99+ [switch ] $SkipIfMissing
96100 )
97101
98102 $startSegment = " <!-- $Name `_START -->"
99103 $endSegment = " <!-- $Name `_END -->"
104+
105+ if (-not (Test-Path - Path $Path )) {
106+ if ($SkipIfMissing ) {
107+ Write-Warning " [$Name ] Skipping update because target file was not found: $Path "
108+ return
109+ }
110+
111+ throw " [$Name ] Target file was not found: $Path "
112+ }
113+
100114 $currentContent = Get-Content - Path $Path
101115 $startIndex = $currentContent.IndexOf ($startSegment )
102116 $endIndex = $currentContent.IndexOf ($endSegment )
103117
104118 if ($startIndex -lt 0 ) {
119+ if ($SkipIfMissing ) {
120+ Write-Warning " [$Name ] Skipping update because the start marker was not found in: $Path "
121+ return
122+ }
123+
105124 throw " [$Name ] The start comment segment was not found in the file."
106125 }
107126 if ($endIndex -lt 0 ) {
127+ if ($SkipIfMissing ) {
128+ Write-Warning " [$Name ] Skipping update because the end marker was not found in: $Path "
129+ return
130+ }
131+
108132 throw " [$Name ] The end comment segment was not found in the file."
109133 }
110134 if ($endIndex -lt $startIndex ) {
135+ if ($SkipIfMissing ) {
136+ Write-Warning " [$Name ] Skipping update because marker order is invalid in: $Path "
137+ return
138+ }
139+
111140 throw " [$Name ] The end comment segment was found before the start comment segment."
112141 }
113142
@@ -173,7 +202,7 @@ function Update-ActionList {
173202$actionTableRows </table>
174203
175204"@
176- Update-MDSection - Path ' .\src\docs\GitHub-Actions\index.md' - Name ' ACTION_LIST' - Content $actionTable
205+ Update-MDSection - Path ' .\src\docs\GitHub-Actions\index.md' - Name ' ACTION_LIST' - Content $actionTable - SkipIfMissing
177206}
178207
179208function Update-ModuleList {
@@ -229,7 +258,7 @@ $moduleTableRows</table>
229258
230259"@
231260
232- Update-MDSection - Path ' .\src\docs\PowerShell\Modules\index.md' - Name ' MODULE_LIST' - Content $moduleTable
261+ Update-MDSection - Path ' .\src\docs\PowerShell\Modules\index.md' - Name ' MODULE_LIST' - Content $moduleTable - SkipIfMissing
233262}
234263
235264function Update-FunctionAppList {
@@ -289,5 +318,5 @@ $functionAppTableRows</table>
289318
290319"@
291320
292- Update-MDSection - Path ' .\src\docs\PowerShell\FunctionApps\index.md' - Name ' FUNCTIONAPP_LIST' - Content $functionAppTable
321+ Update-MDSection - Path ' .\src\docs\PowerShell\FunctionApps\index.md' - Name ' FUNCTIONAPP_LIST' - Content $functionAppTable - SkipIfMissing
293322}
0 commit comments