Skip to content

Commit 5e207aa

Browse files
authored
Update AzF profile to be useful (#1341)
* Fix collection issue * Update AzF profile to be useful * Fix alias
1 parent c393de4 commit 5e207aa

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed

PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PowerShellDataCollector.cs

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private PowerShellDataCollector(
8484
internal ReadOnlySet<string> CommonParameterNames => _lazyCommonParameters.Value;
8585

8686
/// <summary>
87-
/// Assembly module data objects into a lookup table.
87+
/// Assemble module data objects into a lookup table.
8888
/// </summary>
8989
/// <param name="modules">An enumeration of module data objects to assemble</param>
9090
/// <returns>A case-insensitive dictionary of versioned module data objects.</returns>
@@ -96,7 +96,10 @@ public JsonCaseInsensitiveStringDictionary<JsonDictionary<Version, ModuleData>>
9696
{
9797
if (moduleDict.TryGetValue(module.Item1, out JsonDictionary<Version, ModuleData> versionDict))
9898
{
99-
versionDict.Add(module.Item2, module.Item3);
99+
if (!versionDict.ContainsKey(module.Item2))
100+
{
101+
versionDict[module.Item2] = module.Item3;
102+
}
100103
continue;
101104
}
102105

@@ -144,9 +147,12 @@ public IEnumerable<Tuple<string, Version, ModuleData>> GetModulesData(out IEnume
144147

145148
Tuple<string, Version, ModuleData> moduleData = LoadAndGetModuleData(module, out Exception error);
146149

147-
if (moduleData == null && error != null)
150+
if (moduleData == null)
148151
{
149-
errs.Add(error);
152+
if (error != null)
153+
{
154+
errs.Add(error);
155+
}
150156
continue;
151157
}
152158

@@ -174,6 +180,12 @@ public Tuple<string, Version, ModuleData> LoadAndGetModuleData(PSModuleInfo modu
174180
.InvokeAndClear<PSModuleInfo>()
175181
.FirstOrDefault();
176182

183+
if (importedModule == null)
184+
{
185+
error = null;
186+
return null;
187+
}
188+
177189
Tuple<string, Version, ModuleData> moduleData = GetSingleModuleData(importedModule);
178190

179191
_pwsh.AddCommand(s_rmoInfo)
@@ -281,11 +293,26 @@ public Tuple<string, Version, ModuleData> GetCoreModuleData()
281293
switch (command)
282294
{
283295
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+
}
285304
continue;
286305

287306
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+
}
289316
continue;
290317

291318
default:
@@ -495,32 +522,8 @@ public FunctionData GetSingleFunctionData(FunctionInfo function)
495522
try
496523
{
497524
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-
{
506525
functionData.OutputType = GetOutputType(function.OutputType);
507-
}
508-
catch (RuntimeException)
509-
{
510-
// Also can fail
511-
}
512-
513-
try
514-
{
515526
functionData.ParameterSets = GetParameterSets(function.ParameterSets);
516-
}
517-
catch (RuntimeException)
518-
{
519-
// Type resolution failure
520-
}
521-
522-
try
523-
{
524527
AssembleParameters(
525528
function.Parameters,
526529
out JsonCaseInsensitiveStringDictionary<ParameterData> parameters,
@@ -532,7 +535,7 @@ public FunctionData GetSingleFunctionData(FunctionInfo function)
532535
}
533536
catch (RuntimeException)
534537
{
535-
// Can fail
538+
// This can fail when PowerShell can't resolve a type. So we just leave the field null
536539
}
537540

538541
return functionData;

PSCompatibilityCollector/optional_profiles/azurefunctions.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)