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

Defending code #13696

Merged
merged 2 commits into from
Jan 24, 2023
Merged
Changes from all 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
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
Expand Down Expand Up @@ -137,9 +137,9 @@ internal void DependencyRegen(WorkspaceModel ws, bool forceCompute = false)
RestartBanner.Visibility = Visibility.Hidden;
ws.ForceComputeWorkspaceReferences = forceCompute;

var packageDependencies = ws.NodeLibraryDependencies.Where(d => d is PackageDependencyInfo).ToList();
var localDefinitions = ws.NodeLocalDefinitions.Where(d => d is DependencyInfo).ToList();
var externalFiles = ws.ExternalFiles.Where(d => d is DependencyInfo).ToList();
var packageDependencies = ws.NodeLibraryDependencies?.Where(d => d is PackageDependencyInfo).ToList();
var localDefinitions = ws.NodeLocalDefinitions?.Where(d => d is DependencyInfo).ToList();
var externalFiles = ws.ExternalFiles?.Where(d => d is DependencyInfo).ToList();

foreach (DependencyInfo info in localDefinitions)
{
Expand Down Expand Up @@ -187,9 +187,16 @@ internal void DependencyRegen(WorkspaceModel ws, bool forceCompute = false)
foreach (var package in dependencyViewExtension.pmExtension.PackageLoader.LocalPackages.Where(x =>
x.LoadState.ScheduledState == PackageLoadState.ScheduledTypes.ScheduledForDeletion || x.LoadState.ScheduledState == PackageLoadState.ScheduledTypes.ScheduledForUnload))
{
(packageDependencies.FirstOrDefault(x => x.Name == package.Name) as PackageDependencyInfo).State =
Copy link
Member

@mjkkirschner mjkkirschner Jan 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice above that ws and its properties are never checked for being null... seems that would be valuable at the start of the function - you can probably use ? for most of it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

try
{
(packageDependencies.FirstOrDefault(x => x.Name == package.Name) as PackageDependencyInfo).State =
PackageDependencyState.RequiresRestart;
hasPackageMarkedForUninstall = true;
hasPackageMarkedForUninstall = true;
}
catch (Exception ex)
{
dependencyViewExtension.OnMessageLogged(LogMessage.Info(string.Format(Properties.Resources.DependencyViewExtensionErrorTemplate, $"failure to set package uninstall state |{ ex.ToString()}")));
}
}

RestartBanner.Visibility = hasPackageMarkedForUninstall ? Visibility.Visible: Visibility.Hidden;
Expand All @@ -200,10 +207,17 @@ internal void DependencyRegen(WorkspaceModel ws, bool forceCompute = false)
{
foreach (PackageDependencyInfo packageDependencyInfo in packageDependencies)
{
var targetInfo = pmExtension.PackageLoader.LocalPackages.Where(x => x.Name == packageDependencyInfo.Name).FirstOrDefault();
if (targetInfo != null)
try
{
var targetInfo = pmExtension.PackageLoader.LocalPackages.Where(x => x.Name == packageDependencyInfo.Name).FirstOrDefault();
if (targetInfo != null)
{
packageDependencyInfo.Path = targetInfo.RootDirectory;
Copy link
Member

@mjkkirschner mjkkirschner Jan 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it cause problems for this to be left null if an exception is caught? should it be to set to empty string or something? I don't actually know if it's null - just something to consider.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be null

imagen

}
}
catch (Exception ex)
{
packageDependencyInfo.Path = targetInfo.RootDirectory;
dependencyViewExtension.OnMessageLogged(LogMessage.Info(string.Format(Properties.Resources.DependencyViewExtensionErrorTemplate, ex.ToString())));
}
}
}
Expand Down