Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzart90 committed Apr 26, 2024
1 parent 8dfb8be commit 1e2b79c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -879,17 +879,20 @@ private void CrashGracefully(Exception ex, bool fatal = false)
{
try
{
Console.WriteLine($"CrashGracefully + {fatal}");
var exceptionAssembly = ex.TargetSite?.Module?.Assembly;
// Do not crash if the exception is coming from a 3d party package;
if (!fatal && exceptionAssembly != null)
{
Console.WriteLine($"exceptionAssembly + {exceptionAssembly.FullName}");

// Check if the exception might be coming from a loaded package assembly.
var faultyPkg = Model.GetPackageManagerExtension()?.PackageLoader?.LocalPackages?.FirstOrDefault(p =>
{
return exceptionAssembly.Location.StartsWith(p.RootDirectory, StringComparison.OrdinalIgnoreCase);
}
);

Console.WriteLine($"FaultyPackage + {faultyPkg?.Name ?? "Not found"}");
if (faultyPkg != null)
{
var crashDetails = new CrashErrorReportArgs(ex);
Expand All @@ -898,6 +901,10 @@ private void CrashGracefully(Exception ex, bool fatal = false)
return;
}
}
else
{
Console.WriteLine($"IsCrashing for real");
}

DynamoModel.IsCrashing = true;
var crashData = new CrashErrorReportArgs(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ public void TestCrashInPackage()
var loader = currentDynamoModel.GetPackageManagerExtension().PackageLoader;

var pkg = loader.ScanPackageDirectory(pkgDir);
Assert.IsNotNull(pkg);

int count = 0;
void DynamoConsoleLogger_LogErrorToDynamoConsole(string obj)
Expand All @@ -339,12 +340,29 @@ void DynamoConsoleLogger_LogErrorToDynamoConsole(string obj)
Assert.IsFalse(DynamoModel.IsCrashing);

DynamoConsoleLogger.LogErrorToDynamoConsole += DynamoConsoleLogger_LogErrorToDynamoConsole;
Assert.Throws<NotImplementedException>(() =>

NotImplementedException expectedEx = null;
try
{
loader.LoadPackages(new List<Package>() { pkg });

var loadedPkg = currentDynamoModel.GetPackageManagerExtension()?.PackageLoader?.LocalPackages?.FirstOrDefault(p =>
{
return p.RootDirectory.EndsWith("SampleViewExtension_Crash", StringComparison.OrdinalIgnoreCase);
});

Assert.AreEqual(PackageLoadState.StateTypes.Loaded, loadedPkg.LoadState.State);

DispatcherUtil.DoEventsLoop(() => count > 0);
});
}
catch (NotImplementedException ex)
{
expectedEx = ex;
}

Assert.IsNotNull(expectedEx);
Assert.IsNotNull(expectedEx.TargetSite?.Module?.Assembly);
Assert.IsTrue(expectedEx.TargetSite?.Module?.Assembly.Location.StartsWith(pkg.RootDirectory, StringComparison.OrdinalIgnoreCase));
Assert.IsFalse(DynamoModel.IsCrashing);
Assert.AreEqual(1, count);

Expand Down

0 comments on commit 1e2b79c

Please sign in to comment.