Skip to content

Fix ArgumentNullException when Generating without docs -NoDocs switch#711

Merged
dolauli merged 2 commits intoAzure:masterfrom
georgend:master
Nov 20, 2020
Merged

Fix ArgumentNullException when Generating without docs -NoDocs switch#711
dolauli merged 2 commits intoAzure:masterfrom
georgend:master

Conversation

@georgend
Copy link
Contributor

Currently the code path below, throws ArgumentNullException when Export-ProxyCmdlet is invoked in the -NoDocs code path.

if($NoDocs) {
Write-Host -ForegroundColor Green 'Creating exports...'
Export-ProxyCmdlet -ModuleName $moduleName -ModulePath $modulePaths -ExportsFolder $exportsFolder -InternalFolder $internalFolder -ExcludeDocs
} else {
Write-Host -ForegroundColor Green 'Creating exports and docs...'
$moduleDescription = '${$project.metadata.description}'
$docsFolder = Join-Path $PSScriptRoot '${$lib.path.relative($project.baseFolder, $project.docsFolder)}'
if(Test-Path $docsFolder) {
$null = Get-ChildItem -Path $docsFolder -Recurse -Exclude 'readme.md' | Remove-Item -Recurse -ErrorAction SilentlyContinue
}
$null = New-Item -ItemType Directory -Force -Path $docsFolder
Export-ProxyCmdlet -ModuleName $moduleName -ModulePath $modulePaths -ExportsFolder $exportsFolder -InternalFolder $internalFolder -ModuleDescription $moduleDescription -DocsFolder $docsFolder -ExamplesFolder $examplesFolder -ModuleGuid $guid

Exception is thrown here at Path.Combine, since ExamplesFolder will be null.
var examplesFolder = isValidProfile ? Path.Combine(ExamplesFolder, variantGroup.ProfileName) : ExamplesFolder;

Solution
Allow ExamplesFolder to be passed along for all param sets, since examples are already always generated. (Example Stubs).

[Parameter(Mandatory = true, ParameterSetName = "Docs")]
[ValidateNotNullOrEmpty]
public string ExamplesFolder { get; set; }

Pass along -ExamplesFolder since its required in all code paths.

George Ndungu added 2 commits November 18, 2020 16:10
…ures.

Pass along `-ExamplesFolder` since its required in all code paths.
@georgend georgend marked this pull request as ready for review November 18, 2020 13:17
@dolauli
Copy link
Contributor

dolauli commented Nov 19, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Contributor

@dolauli dolauli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@dolauli dolauli merged commit 808c16f into Azure:master Nov 20, 2020
dolauli pushed a commit to dolauli/autorest.powershell that referenced this pull request Nov 23, 2020
…ch (Azure#711)

* Fix ArgumentNullException when Generating without docs `-NoDocs` features.
Pass along `-ExamplesFolder` since its required in all code paths.

* Make examples mandatory, for all paramsets

Co-authored-by: George Ndungu <gendungu@microsoft.com>
dolauli added a commit that referenced this pull request Nov 23, 2020
…ch (#711) (#712)

* Fix ArgumentNullException when Generating without docs `-NoDocs` features.
Pass along `-ExamplesFolder` since its required in all code paths.

* Make examples mandatory, for all paramsets

Co-authored-by: George Ndungu <gendungu@microsoft.com>

Co-authored-by: George <1641829+finsharp@users.noreply.github.com>
Co-authored-by: George Ndungu <gendungu@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants