diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bb90375..38008509 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ### Changed - `Deploy-NovaPackage` now shows a concise resolved-upload summary before execution, reports progress while multiple artifacts are uploading, and prints a short completion summary with a suggested verification step after successful raw uploads. +- `Get-NovaProjectInfo` now fails with clearer recovery guidance when `-Path` does not exist, points to a file, or the target folder is missing `project.json`. ### Deprecated diff --git a/RELEASE_NOTE.md b/RELEASE_NOTE.md index 811fba62..049257a5 100644 --- a/RELEASE_NOTE.md +++ b/RELEASE_NOTE.md @@ -14,6 +14,7 @@ This file summarizes the release notes for NovaModuleTools. **UNRELEASED** chang ### Changed - `Deploy-NovaPackage` now shows clearer terminal feedback during raw package uploads, including a concise pre-flight summary, progress across multiple artifacts, and a short verification hint after success. +- `Get-NovaProjectInfo` now explains how to recover when `-Path` is invalid or the target folder is not a Nova project root. ### Deprecated @@ -21,7 +22,7 @@ This file summarizes the release notes for NovaModuleTools. **UNRELEASED** chang ### Fixed -- PowerShell command help `RELATED LINKS` now use valid help-topic links instead of GitHub blob pages. +- PowerShell command help `RELATED LINKS` now use valid help-topic. ### Security diff --git a/docs/NovaModuleTools/en-US/Get-NovaProjectInfo.md b/docs/NovaModuleTools/en-US/Get-NovaProjectInfo.md index e32f931d..3674e6c6 100644 --- a/docs/NovaModuleTools/en-US/Get-NovaProjectInfo.md +++ b/docs/NovaModuleTools/en-US/Get-NovaProjectInfo.md @@ -50,6 +50,9 @@ When you use `-Version`, the command returns only the project version string ins When you use `-Installed`, the command returns the installed `NovaModuleTools` module name and version string instead of project metadata. +When `-Path` does not resolve to an existing project root folder, or the folder does not contain `project.json`, +the command fails with an actionable error that tells you how to recover. + ## EXAMPLES ### EXAMPLE 1 @@ -185,6 +188,9 @@ Returned by default. The object includes project metadata, defaulted build setti This command throws a clear error when `project.json` is missing or empty. +If `-Path` points to a file or a folder that does not exist, `Get-NovaProjectInfo` tells you to rerun it from a +Nova project root or pass `-Path` to the folder that contains `project.json`. + `-Installed` does not require a project path or a `project.json` file. ## RELATED LINKS diff --git a/src/private/shared/GetNovaProjectInfoContext.ps1 b/src/private/shared/GetNovaProjectInfoContext.ps1 index 032cf408..840a6a4a 100644 --- a/src/private/shared/GetNovaProjectInfoContext.ps1 +++ b/src/private/shared/GetNovaProjectInfoContext.ps1 @@ -4,11 +4,9 @@ function Get-NovaProjectInfoContext { [Parameter(Mandatory)][string]$Path ) - $projectRoot = (Resolve-Path -LiteralPath $Path).Path + $projectRoot = Resolve-NovaProjectInfoRootPath -Path $Path $projectJson = [System.IO.Path]::Join($projectRoot, 'project.json') - if (-not (Test-Path -LiteralPath $projectJson)) { - Stop-NovaOperation -Message "Not a project folder. project.json not found: $projectJson" -ErrorId 'Nova.Environment.ProjectJsonNotFound' -Category ObjectNotFound -TargetObject $projectJson - } + Assert-NovaProjectJsonPresence -ProjectRoot $projectRoot -ProjectJson $projectJson return [pscustomobject]@{ ProjectRoot = $projectRoot @@ -16,3 +14,34 @@ function Get-NovaProjectInfoContext { JsonData = Read-ProjectJsonData -ProjectJsonPath $projectJson } } + +function Resolve-NovaProjectInfoRootPath { + [CmdletBinding()] + param( + [Parameter(Mandatory)][string]$Path + ) + + try { + $resolvedPath = (Resolve-Path -LiteralPath $Path -ErrorAction Stop).Path + } catch { + Stop-NovaOperation -Message "Project path not found: $Path. Run Get-NovaProjectInfo from a Nova project root or pass -Path to an existing project folder." -ErrorId 'Nova.Environment.ProjectPathNotFound' -Category ObjectNotFound -TargetObject $Path + } + + if (-not (Test-Path -LiteralPath $resolvedPath -PathType Container)) { + Stop-NovaOperation -Message "Project path must be a folder: $resolvedPath. Pass -Path to the project root that contains project.json." -ErrorId 'Nova.Environment.ProjectPathNotDirectory' -Category InvalidArgument -TargetObject $resolvedPath + } + + return $resolvedPath +} + +function Assert-NovaProjectJsonPresence { + [CmdletBinding()] + param( + [Parameter(Mandatory)][string]$ProjectRoot, + [Parameter(Mandatory)][string]$ProjectJson + ) + + if (-not (Test-Path -LiteralPath $ProjectJson -PathType Leaf)) { + Stop-NovaOperation -Message "project.json not found in project root: $ProjectRoot. Run Get-NovaProjectInfo from a folder that contains project.json or pass -Path to that folder." -ErrorId 'Nova.Environment.ProjectJsonNotFound' -Category ObjectNotFound -TargetObject $ProjectJson + } +} diff --git a/tests/private/shared/GetNovaProjectInfoContext.Tests.ps1 b/tests/private/shared/GetNovaProjectInfoContext.Tests.ps1 index 8796067a..7d6a9f4e 100644 --- a/tests/private/shared/GetNovaProjectInfoContext.Tests.ps1 +++ b/tests/private/shared/GetNovaProjectInfoContext.Tests.ps1 @@ -15,8 +15,19 @@ Describe 'Get-NovaProjectInfoContext' { Remove-Item -LiteralPath $script:root -Recurse -Force -ErrorAction SilentlyContinue } + It 'throws a clear error when the project path does not exist' { + {Get-NovaProjectInfoContext -Path (Join-Path $script:root 'missing')} | Should -Throw '*Project path not found:*Run Get-NovaProjectInfo from a Nova project root or pass -Path to an existing project folder.*' + } + + It 'throws a clear error when the project path points to a file instead of a folder' { + $filePath = Join-Path $script:root 'project.txt' + Set-Content -LiteralPath $filePath -Value 'content' + + {Get-NovaProjectInfoContext -Path $filePath} | Should -Throw '*Project path must be a folder:*Pass -Path to the project root that contains project.json.*' + } + It 'throws when project.json is missing in the given folder' { - {Get-NovaProjectInfoContext -Path $script:root} | Should -Throw + {Get-NovaProjectInfoContext -Path $script:root} | Should -Throw '*project.json not found in project root:*Run Get-NovaProjectInfo from a folder that contains project.json or pass -Path to that folder.*' } It 'returns the resolved root, project.json path, and parsed JSON data' {