Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPS13 Export-MamlCommandHelp creates invalid XML #692

Open
3 tasks done
sdwheeler opened this issue Oct 14, 2024 · 1 comment
Open
3 tasks done

OPS13 Export-MamlCommandHelp creates invalid XML #692

sdwheeler opened this issue Oct 14, 2024 · 1 comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@sdwheeler
Copy link
Collaborator

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

It looks like there is extra (incomplete) XML at the end the file.

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

image

@sdwheeler sdwheeler added the Needs-Triage The issue is new and needs to be triaged by a work group. label Oct 14, 2024
@sdwheeler sdwheeler added this to the Planned for CabGen milestone Oct 14, 2024
@sdwheeler
Copy link
Collaborator Author

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 sdwheeler changed the title OPS12 Export-MamlCommandHelp creates invalid XML OPS13 Export-MamlCommandHelp creates invalid XML Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

No branches or pull requests

1 participant