@@ -84,7 +84,7 @@ private PowerShellDataCollector(
84
84
internal ReadOnlySet < string > CommonParameterNames => _lazyCommonParameters . Value ;
85
85
86
86
/// <summary>
87
- /// Assembly module data objects into a lookup table.
87
+ /// Assemble module data objects into a lookup table.
88
88
/// </summary>
89
89
/// <param name="modules">An enumeration of module data objects to assemble</param>
90
90
/// <returns>A case-insensitive dictionary of versioned module data objects.</returns>
@@ -96,7 +96,10 @@ public JsonCaseInsensitiveStringDictionary<JsonDictionary<Version, ModuleData>>
96
96
{
97
97
if ( moduleDict . TryGetValue ( module . Item1 , out JsonDictionary < Version , ModuleData > versionDict ) )
98
98
{
99
- versionDict . Add ( module . Item2 , module . Item3 ) ;
99
+ if ( ! versionDict . ContainsKey ( module . Item2 ) )
100
+ {
101
+ versionDict [ module . Item2 ] = module . Item3 ;
102
+ }
100
103
continue ;
101
104
}
102
105
@@ -144,9 +147,12 @@ public IEnumerable<Tuple<string, Version, ModuleData>> GetModulesData(out IEnume
144
147
145
148
Tuple < string , Version , ModuleData > moduleData = LoadAndGetModuleData ( module , out Exception error ) ;
146
149
147
- if ( moduleData == null && error != null )
150
+ if ( moduleData == null )
148
151
{
149
- errs . Add ( error ) ;
152
+ if ( error != null )
153
+ {
154
+ errs . Add ( error ) ;
155
+ }
150
156
continue ;
151
157
}
152
158
@@ -174,6 +180,12 @@ public Tuple<string, Version, ModuleData> LoadAndGetModuleData(PSModuleInfo modu
174
180
. InvokeAndClear < PSModuleInfo > ( )
175
181
. FirstOrDefault ( ) ;
176
182
183
+ if ( importedModule == null )
184
+ {
185
+ error = null ;
186
+ return null ;
187
+ }
188
+
177
189
Tuple < string , Version , ModuleData > moduleData = GetSingleModuleData ( importedModule ) ;
178
190
179
191
_pwsh . AddCommand ( s_rmoInfo )
@@ -281,11 +293,26 @@ public Tuple<string, Version, ModuleData> GetCoreModuleData()
281
293
switch ( command )
282
294
{
283
295
case CmdletInfo cmdlet :
284
- cmdletData . Add ( cmdlet . Name , GetSingleCmdletData ( cmdlet ) ) ;
296
+ try
297
+ {
298
+ cmdletData . Add ( cmdlet . Name , GetSingleCmdletData ( cmdlet ) ) ;
299
+ }
300
+ catch ( RuntimeException )
301
+ {
302
+ // If we can't load the cmdlet, we just move on
303
+ }
285
304
continue ;
286
305
287
306
case FunctionInfo function :
288
- functionData . Add ( function . Name , GetSingleFunctionData ( function ) ) ;
307
+ try
308
+ {
309
+ functionData . Add ( function . Name , GetSingleFunctionData ( function ) ) ;
310
+ }
311
+ catch ( RuntimeException )
312
+ {
313
+ // Some functions have problems loading,
314
+ // which likely means PowerShell wouldn't be able to run them
315
+ }
289
316
continue ;
290
317
291
318
default :
@@ -495,32 +522,8 @@ public FunctionData GetSingleFunctionData(FunctionInfo function)
495
522
try
496
523
{
497
524
functionData . DefaultParameterSet = GetDefaultParameterSet ( function . DefaultParameterSet ) ;
498
- }
499
- catch ( RuntimeException )
500
- {
501
- // This can fail when PowerShell can't resolve a type. So we just leave the field null
502
- }
503
-
504
- try
505
- {
506
525
functionData . OutputType = GetOutputType ( function . OutputType ) ;
507
- }
508
- catch ( RuntimeException )
509
- {
510
- // Also can fail
511
- }
512
-
513
- try
514
- {
515
526
functionData . ParameterSets = GetParameterSets ( function . ParameterSets ) ;
516
- }
517
- catch ( RuntimeException )
518
- {
519
- // Type resolution failure
520
- }
521
-
522
- try
523
- {
524
527
AssembleParameters (
525
528
function . Parameters ,
526
529
out JsonCaseInsensitiveStringDictionary < ParameterData > parameters ,
@@ -532,7 +535,7 @@ public FunctionData GetSingleFunctionData(FunctionInfo function)
532
535
}
533
536
catch ( RuntimeException )
534
537
{
535
- // Can fail
538
+ // This can fail when PowerShell can't resolve a type. So we just leave the field null
536
539
}
537
540
538
541
return functionData ;
0 commit comments