Skip to content

Commit d5ed92a

Browse files
Validate PSModuleInfo properties directly instead of checking pwsh.HadErrors first
Changed validation logic to check Author, Description, and Version properties on the result object directly, rather than only checking them when pwsh.HadErrors is true. This ensures proper validation with CurrentRunspace mode. Co-authored-by: adityapatwardhan <12820925+adityapatwardhan@users.noreply.github.com>
1 parent 158f785 commit d5ed92a

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/code/Utils.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,32 +1400,32 @@ public static bool ValidateModuleManifest(string moduleManifestPath, out string
14001400
}
14011401
}
14021402

1403-
if (pwsh.HadErrors)
1403+
// Validate the result object directly
1404+
if (results.Any())
14041405
{
1405-
if (results.Any())
1406+
PSModuleInfo psModuleInfoObj = results[0].BaseObject as PSModuleInfo;
1407+
if (string.IsNullOrWhiteSpace(psModuleInfoObj.Author))
14061408
{
1407-
PSModuleInfo psModuleInfoObj = results[0].BaseObject as PSModuleInfo;
1408-
if (string.IsNullOrWhiteSpace(psModuleInfoObj.Author))
1409-
{
1410-
errorMsg = "No author was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file.";
1411-
}
1412-
else if (string.IsNullOrWhiteSpace(psModuleInfoObj.Description))
1413-
{
1414-
errorMsg = "No description was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file.";
1415-
}
1416-
else if (psModuleInfoObj.Version == null)
1417-
{
1418-
errorMsg = "No version or an incorrectly formatted version was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file.";
1419-
}
1409+
errorMsg = "No author was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file.";
1410+
return false;
14201411
}
1421-
1422-
if (string.IsNullOrEmpty(errorMsg))
1412+
else if (string.IsNullOrWhiteSpace(psModuleInfoObj.Description))
14231413
{
1424-
// Surface any inner error messages
1425-
var innerErrorMsg = (pwsh.Streams.Error.Count > 0) ? pwsh.Streams.Error[0].ToString() : string.Empty;
1426-
errorMsg = $"Module manifest file validation failed with error: {innerErrorMsg}. Run 'Test-ModuleManifest' to validate the module manifest.";
1414+
errorMsg = "No description was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file.";
1415+
return false;
14271416
}
1428-
1417+
else if (psModuleInfoObj.Version == null)
1418+
{
1419+
errorMsg = "No version or an incorrectly formatted version was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file.";
1420+
return false;
1421+
}
1422+
}
1423+
1424+
// Check for any errors from Test-ModuleManifest
1425+
if (pwsh.HadErrors)
1426+
{
1427+
var innerErrorMsg = (pwsh.Streams.Error.Count > 0) ? pwsh.Streams.Error[0].ToString() : string.Empty;
1428+
errorMsg = $"Module manifest file validation failed with error: {innerErrorMsg}. Run 'Test-ModuleManifest' to validate the module manifest.";
14291429
return false;
14301430
}
14311431
}

0 commit comments

Comments
 (0)