Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AzF profile to be useful #1341

Merged
merged 3 commits into from
Sep 14, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private PowerShellDataCollector(
internal ReadOnlySet<string> CommonParameterNames => _lazyCommonParameters.Value;

/// <summary>
/// Assembly module data objects into a lookup table.
/// Assemble module data objects into a lookup table.
/// </summary>
/// <param name="modules">An enumeration of module data objects to assemble</param>
/// <returns>A case-insensitive dictionary of versioned module data objects.</returns>
Expand All @@ -96,7 +96,10 @@ public JsonCaseInsensitiveStringDictionary<JsonDictionary<Version, ModuleData>>
{
if (moduleDict.TryGetValue(module.Item1, out JsonDictionary<Version, ModuleData> versionDict))
{
versionDict.Add(module.Item2, module.Item3);
if (!versionDict.ContainsKey(module.Item2))
{
versionDict[module.Item2] = module.Item3;
}
continue;
}

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

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

if (moduleData == null && error != null)
if (moduleData == null)
{
errs.Add(error);
if (error != null)
{
errs.Add(error);
}
continue;
}

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

if (importedModule == null)
{
error = null;
return null;
}

Tuple<string, Version, ModuleData> moduleData = GetSingleModuleData(importedModule);

_pwsh.AddCommand(s_rmoInfo)
Expand Down Expand Up @@ -281,11 +293,26 @@ public Tuple<string, Version, ModuleData> GetCoreModuleData()
switch (command)
{
case CmdletInfo cmdlet:
cmdletData.Add(cmdlet.Name, GetSingleCmdletData(cmdlet));
try
{
cmdletData.Add(cmdlet.Name, GetSingleCmdletData(cmdlet));
}
catch (RuntimeException)
{
// If we can't load the cmdlet, we just move on
}
continue;

case FunctionInfo function:
functionData.Add(function.Name, GetSingleFunctionData(function));
try
{
functionData.Add(function.Name, GetSingleFunctionData(function));
}
catch (RuntimeException)
{
// Some functions have problems loading,
// which likely means PowerShell wouldn't be able to run them
}
continue;

default:
Expand Down Expand Up @@ -495,32 +522,8 @@ public FunctionData GetSingleFunctionData(FunctionInfo function)
try
{
functionData.DefaultParameterSet = GetDefaultParameterSet(function.DefaultParameterSet);
}
catch (RuntimeException)
{
// This can fail when PowerShell can't resolve a type. So we just leave the field null
}

try
{
functionData.OutputType = GetOutputType(function.OutputType);
}
catch (RuntimeException)
{
// Also can fail
}

try
{
functionData.ParameterSets = GetParameterSets(function.ParameterSets);
}
catch (RuntimeException)
{
// Type resolution failure
}

try
{
AssembleParameters(
function.Parameters,
out JsonCaseInsensitiveStringDictionary<ParameterData> parameters,
Expand All @@ -532,7 +535,7 @@ public FunctionData GetSingleFunctionData(FunctionInfo function)
}
catch (RuntimeException)
{
// Can fail
// This can fail when PowerShell can't resolve a type. So we just leave the field null
}

return functionData;
Expand Down

Large diffs are not rendered by default.