platyPS
platyPS copied to clipboard
OPS13 Export-MamlCommandHelp creates invalid XML
Prerequisites
- [X] Write a descriptive title.
- [X] Make sure you are able to repro it on the latest released version
- [X] Search the existing issues.
Steps to reproduce
It looks like there is extra (incomplete) XML at the end the file.
- Example corrupt file: Microsoft.PowerShell.PlatyPS-Help.zip
It appears that the file ends on line 3450 but there is extra content after.
Expected behavior
$mdfiles = Measure-PlatyPSMarkdown -Path .\Microsoft.PowerShell.PlatyPS\*.md
$mdfiles | Where-Object Filetype -match 'CommandHelp' |
Import-MarkdownCommandHelp -Path {$_.FilePath} |
Export-MamlCommandHelp -OutputFolder .\maml
$x = [xml](gc .\maml\Microsoft.PowerShell.PlatyPS\Microsoft.PowerShell.PlatyPS-Help.xml)
Actual behavior
InvalidArgument: Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type."
Error details
See attached screen shot
Environment data
OPS12 build
Visuals
New repo steps.
$v1path = 'D:\Git\PS-Docs\PowerShell-Docs\reference\7.4'
$v2path = '.\v2'
# Convert v1 Markdown to v2
dir $v1path -Recurse -Filter *.md |
Measure-PlatyPSMarkdown |
ForEach-Object {
if ($_.Filetype -match 'CommandHelp') {
Import-MarkdownCommandHelp -Path $_.FilePath |
Export-MarkdownCommandHelp -OutputFolder $v2path -Force
} elseif ($_.Filetype -match 'ModuleFile') {
Import-MarkdownModuleFile -Path $_.FilePath |
Export-MarkdownModuleFile -OutputFolder $v2path -Force
}
}
# Convert to MAML - Import all markdown at once and stream conversion.
dir v2\*.md -rec |
Measure-PlatyPSMarkdown |
Where-Object Filetype -match 'CommandHelp' |
Import-MarkdownCommandHelp -Path {$_.FilePath} |
Export-MamlCommandHelp -OutputFolder .\maml -Force -Verbose
Error output
VERBOSE: Performing the operation "Export-MamlCommandHelp" on target ".\maml".
VERBOSE: Performing the operation "Export-MamlCommandHelp" on target "CimCmdlets-Help.xml".
Directory: D:\Git\PS-Src\platyPS\v2docs\OPS13\maml\CimCmdlets
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 10/26/2024 12:45 PM 502616 CimCmdlets-Help.xml
VERBOSE: Performing the operation "Export-MamlCommandHelp" on target "Microsoft.PowerShell.Archive-Help.xml".
Directory: D:\Git\PS-Src\platyPS\v2docs\OPS13\maml\Microsoft.PowerShell.Archive
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 10/26/2024 12:45 PM 68746 Microsoft.PowerShell.Archive-Help.xml
VERBOSE: Performing the operation "Export-MamlCommandHelp" on target "Microsoft.PowerShell.Core-Help.xml".
Export-MamlCommandHelp:
Line |
5 | Export-MamlCommandHelp -OutputFolder .\maml -Force -Verbose
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Index was outside the bounds of the array.
VERBOSE: Performing the operation "Export-MamlCommandHelp" on target ".\maml".
VERBOSE: Performing the operation "Export-MamlCommandHelp" on target "CimCmdlets-Help.xml".
Directory: D:\Git\PS-Src\platyPS\v2docs\OPS13\maml\CimCmdlets
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 10/26/2024 12:45 PM 502616 CimCmdlets-Help.xml
VERBOSE: Performing the operation "Export-MamlCommandHelp" on target "Microsoft.PowerShell.Archive-Help.xml".
Directory: D:\Git\PS-Src\platyPS\v2docs\OPS13\maml\Microsoft.PowerShell.Archive
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 10/26/2024 12:45 PM 68746 Microsoft.PowerShell.Archive-Help.xml
VERBOSE: Performing the operation "Export-MamlCommandHelp" on target "Microsoft.PowerShell.Core-Help.xml".
Export-MamlCommandHelp:
Line |
5 | Export-MamlCommandHelp -OutputFolder .\maml -Force -Verbose
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Index was outside the bounds of the array.
Get-Error output
Exception :
Type : System.IndexOutOfRangeException
TargetSite :
Name : ConvertCommandDetails
DeclaringType : [Microsoft.PowerShell.PlatyPS.MAML.MamlConversionHelper]
MemberType : Method
Module : Microsoft.PowerShell.PlatyPS.dll
Message : Index was outside the bounds of the array.
Source : Microsoft.PowerShell.PlatyPS
HResult : -2146233080
StackTrace :
at Microsoft.PowerShell.PlatyPS.MAML.MamlConversionHelper.ConvertCommandDetails(CommandHelp commandHelp) in
D:\Git\PS-Src\platyPS\src\MamlWriter\MamlHelpers.cs:line 220
at Microsoft.PowerShell.PlatyPS.MAML.MamlConversionHelper.ConvertCommandHelpToMamlCommand(CommandHelp commandHelp)
in D:\Git\PS-Src\platyPS\src\MamlWriter\MamlHelpers.cs:line 54
at Microsoft.PowerShell.PlatyPS.MAML.MamlConversionHelper.ConvertCommandHelpToMamlHelpItems(List`1 commandHelp) in
D:\Git\PS-Src\platyPS\src\MamlWriter\MamlHelpers.cs:line 43
at Microsoft.PowerShell.PlatyPS.ExportMamlCommandHelpCommand.EndProcessing() in
D:\Git\PS-Src\platyPS\src\Command\ExportMamlCommandHelp.cs:line 86
at System.Management.Automation.CommandProcessorBase.Complete()
CategoryInfo : NotSpecified: (:) [Export-MamlCommandHelp], IndexOutOfRangeException
FullyQualifiedErrorId : System.IndexOutOfRangeException,Microsoft.PowerShell.PlatyPS.ExportMamlCommandHelpCommand
InvocationInfo :
MyCommand : Export-MamlCommandHelp
ScriptLineNumber : 5
OffsetInLine : 5
HistoryId : 157
Line : Export-MamlCommandHelp -OutputFolder .\maml -Force -Verbose
Statement : Export-MamlCommandHelp -OutputFolder .\maml -Force -Verbose
PositionMessage : At line:5 char:5
+ Export-MamlCommandHelp -OutputFolder .\maml -Force -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Export-MamlCommandHelp
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
Now convert to MAML one folder at a time. The works without error.
## Convert to MAML - Import and convert one folder at a time.
dir v2\* -dir | ForEach-Object {
dir $_\*-*.md |
Measure-PlatyPSMarkdown |
Where-Object Filetype -match 'CommandHelp' |
Import-MarkdownCommandHelp -Path {$_.FilePath} |
Export-MamlCommandHelp -OutputFolder .\maml -Force -Verbose
}
@sdwheeler - can you try a repro again. I was not able to reproduce the issue.
No repo in preview.4. Closing.