Get-WinGetManifest logic is broken around how it performs path detection
@RDMacLachlan ya está trabajando en esto.
Desde el 5/10/2022.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
Brief description of your issue
When processing files in a directory, $PathChildItemsJSON and/or $PathChildItemsYAML may be null. This is not accounted for in the subsequent if/else statements that perform validation. If one or the other is null, this will fail internally because of null references. Strict mode is not enabled for these scripts, so the failure cause is not obvious to the caller:
VERBOSE: Path pointed to a directory, found 0 JSON files, and 0 YAML files.
Get-WinGetManifest: D:\b\winget-cli-restsource-ameltzer\bin\Library\Add-WinGetManifest.ps1:109:32
Line |
109 | $ApplicationManifest = Get-WinGetManifest -Path $Path
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Directory does not contain any combination of JSON and YAML files.
VERBOSE: Returning (0) manifests based on search.
Exception: D:\b\winget-cli-restsource-ameltzer\bin\Library\Add-WinGetManifest.ps1:111:13
Line |
111 | throw "Failed to retrieve a proper manifest. Verify and t …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Failed to retrieve a proper manifest. Verify and try again.
This gives the appearance of there being no YAML or JSON files, but there's actually 4 yaml files in my directory. Running again with Set-StrictMode -Version Latest shows detailed failure information:
VERBOSE: Retrieving a copy of the app Manifest file for submission to WinGet source.
PropertyNotFoundException: D:\b\winget-cli-restsource-ameltzer\bin\Library\Get-WinGetManifest.ps1:162:77
Line |
162 | … ath pointed to a directory, found $($PathChildItemsJSON.count) JSON f …
| ~~~~~~~~~~~~~~~~~~~~~~~~~
| The property 'count' cannot be found on this object. Verify that the property exists.
VERBOSE: Path pointed to a directory, found JSON files, and 4 YAML files.
PropertyNotFoundException: D:\b\winget-cli-restsource-ameltzer\bin\Library\Get-WinGetManifest.ps1:166:24
Line |
166 | … if($PathChildItemsJSON.count -eq 0 -and $PathChildItemsYAML. …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The property 'count' cannot be found on this object. Verify that the property exists.
InvalidOperation: D:\b\winget-cli-restsource-ameltzer\bin\Library\Get-WinGetManifest.ps1:264:25
Line |
264 | switch ($ManifestFileType) {
| ~~~~~~~~~~~~~~~~~
| The variable '$ManifestFileType' cannot be retrieved because it has not been set.
This can be fixed by doing this:
$PathChildItemsJSON = Get-ChildItem -Path $Path -Filter "*.json" -ErrorAction SilentlyContinue
if (!$PathChildItemsJSON) {
$PathChildItemsJSON = @()
}
$PathChildItemsYAML = Get-ChildItem -Path $Path -Filter "*.yaml" -ErrorAction SilentlyContinue
if (!$PathChildItemsYAML) {
$PathChildItemsYAML = @()
}
Unfortunately, while fixing this works around the null reference issues, it then runs into #179 :(
VERBOSE: Retrieving a copy of the app Manifest file for submission to WinGet source.
VERBOSE: Path pointed to a directory, found 0 JSON files, and 4 YAML files.
VERBOSE: Single YAML has been found in the specified directory.
Get-WinGetManifest: D:\b\winget-cli-restsource-ameltzer\bin\Library\Add-WinGetManifest.ps1:109:32
Line |
109 | $ApplicationManifest = Get-WinGetManifest -Path $Path
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Unable to process YAML files. Re-import the module to reload the required dependencies.
VERBOSE: Returning (0) manifests based on search.
Exception: D:\b\winget-cli-restsource-ameltzer\bin\Library\Add-WinGetManifest.ps1:111:13
Line |
111 | throw "Failed to retrieve a proper manifest. Verify and t …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Failed to retrieve a proper manifest. Verify and try again.
Steps to reproduce
Run Add-WinGetManifest and point to a path with .yaml documents.
- Lenguaje dominante
- C#
- Estrellas
- 317
- Forks
- 79
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/winget-cli-restsource
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
-
Issue-Feature
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
-
Font Support AbiertoIssue-Feature
microsoft/winget-cli-restsource#310 · 1 comentario · 1 asignado ·
-
Issue Deploying in GCC-H AbiertoIssue-Bug
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
microsoft/winget-cli-restsource#309 · 2 comentarios ·
Todos los issues de microsoft/winget-cli-restsource
Issues similares
-
effort:S P3 refactor
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
nightscout/nocturne#1532 ·
-
core dependencies
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
C#/.NET Roslyn LSP Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
Suspicious code fragments Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
DotNetNext/SqlSugar#1458 ·