Skip to content

Commit

Permalink
ShouldThrowValidationDependencyExceptionOnLoadAssemblyIfExternalExcep…
Browse files Browse the repository at this point in the history
…tionOccurs -> FAIL
  • Loading branch information
LBoullosa committed May 25, 2024
1 parent 0d909c1 commit 3d64b97
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ public static TheoryData AssemblyLoadValidationDependencyExceptions()
{
return new TheoryData<Exception>
{
new ArgumentException(),
new ArgumentNullException(),
new PathTooLongException(),
new ArgumentException()
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using System.IO;
using System;
using System.Reflection;
using System.Security;
using STX.SPAL.Core.Models.Services.Foundations.Assemblies.Exceptions;
using Xeptions;
using System.Runtime.InteropServices;

namespace STX.SPAL.Core.Services.Foundations.Assemblies
{
Expand All @@ -24,6 +28,59 @@ private static Assembly TryCatch(ReturningAssemblyFunction returningAssemblyFunc
throw CreateAssemblyValidationException(
invalidAssemblyPathException);
}

catch (SecurityException securityException)
{
throw CreateAssemblyDependencyException(
securityException);
}

catch (FileLoadException fileLoadException)
{
throw CreateAssemblyDependencyException(
fileLoadException);
}

catch (FileNotFoundException fileNotFoundException)
{
throw CreateAssemblyDependencyException(
fileNotFoundException);
}

catch (BadImageFormatException badImageFormatException)
{
throw CreateAssemblyDependencyException(
badImageFormatException);
}

catch (InvalidOperationException invalidOperationException)
{
throw CreateAssemblyDependencyException(
invalidOperationException);
}

catch (NotSupportedException notSupportedException)
{
throw CreateAssemblyDependencyException(
notSupportedException);
}

catch (IOException iOException)
{
throw CreateAssemblyDependencyException(iOException);
}

catch (UnauthorizedAccessException unauthorizedAccessException)
{
throw CreateAssemblyDependencyException(
unauthorizedAccessException);
}

catch (ArgumentException argumentException)
{
throw CreateAssemblyDependencyException(
argumentException);
}
}

private static AssemblyValidationException CreateAssemblyValidationException(Xeption exception)
Expand All @@ -32,5 +89,29 @@ private static AssemblyValidationException CreateAssemblyValidationException(Xep
message: "Assembly validation error occurred, fix errors and try again.",
innerException: exception);
}

private static AssemblyDependencyException CreateAssemblyDependencyException(Exception exception)
{
var assemblyLoadException =
new AssemblyLoadException(
message: "Assembly load error occurred, contact support.",
innerException: exception);

return new AssemblyDependencyException(
message: "Assembly dependency error occurred, contact support.",
innerException: assemblyLoadException);
}

private static AssemblyValidationDependencyException CreateAssemblyValidationDependencyException(Exception exception)
{
var assemblyLoadException =
new AssemblyLoadException(
message: "Assembly load error occurred, contact support.",
innerException: exception);

return new AssemblyValidationDependencyException(
message: "Assembly validation dependency error occurred, contact support.",
innerException: assemblyLoadException);
}
}
}

0 comments on commit 3d64b97

Please sign in to comment.