Skip to content

Commit

Permalink
Merge pull request #552 from Lezune/users/Lezune/Foundations-LocalFil…
Browse files Browse the repository at this point in the history
…es-Update

CODE RUB: Foundations LocalFiles Exceptions Update v2.10.1
  • Loading branch information
glhays authored Jun 12, 2024
2 parents 18b23c6 + e473e51 commit 1844472
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ private void ShouldThrowValidationExceptionOnReadIfFilePathIsInvalid(
{
// given
var invalidFileException =
new InvalidLocalFileException();
new InvalidLocalFileException(
message: "Invalid local file error occurred, fix error and try again.");

invalidFileException.AddData(
key: "FilePath",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,23 @@ public static TheoryData DependencyValidationExceptions()

return new TheoryData<Xeption>
{
new LocalFileValidationException(someInnerException),
new LocalFileDependencyValidationException(someInnerException),

new LocalFileValidationException(
message: "Local file validation error occurred, fix error and try again.",
someInnerException),

new LocalFileDependencyValidationException(
message: "Local file dependency validation error occurred, fix the errors and try again.",
someInnerException),

new LocalFileValidationException(
message: "Local file validation error occurred, fix error and try again.",
someInnerException),

new LocalFileDependencyValidationException(
message: "Local file dependency validation error occurred, fix the errors and try again.",
someInnerException),

new AIFileValidationException(someInnerException),
new AIFileDependencyValidationException(someInnerException)
};
Expand All @@ -57,8 +72,14 @@ public static TheoryData DependencyExceptions()

return new TheoryData<Xeption>
{
new LocalFileDependencyException(someInnerException),
new LocalFileServiceException(someInnerException),
new LocalFileDependencyException(
message: "Local file dependency error occurred, contact support.",
someInnerException),

new LocalFileServiceException(
message: "Local file service error occurred, contact support.",
someInnerException),

new AIFileDependencyException(someInnerException),
new AIFileServiceException(someInnerException),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.LocalFiles.Exceptions
{
internal class FailedLocalFileDependencyException : Xeption
{
public FailedLocalFileDependencyException(Exception innerException)
: base(
message: "Failed local file error occurred, contact support.",
innerException: innerException)
{ }

public FailedLocalFileDependencyException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.LocalFiles.Exceptions
{
public class FailedLocalFileServiceException : Xeption
{
public FailedLocalFileServiceException(Exception innerException)
: base(
message: "Failed local file service error occurred, contact support.",
innerException: innerException)
{ }

public FailedLocalFileServiceException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.LocalFiles.Exceptions
{
public class InvalidLocalFileException : Xeption
{
public InvalidLocalFileException()
: base(
message: "Invalid local file error occurred, fix error and try again.")
{ }

public InvalidLocalFileException(Exception innerException)
: base(
message: "Invalid local file error occurred, fix error and try again.",
innerException: innerException)
public InvalidLocalFileException(string message)
: base(message)
{ }

public InvalidLocalFileException(string message, Exception innerException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.LocalFiles.Exceptions
{
public class LocalFileDependencyException : Xeption
{
public LocalFileDependencyException(Xeption innerException)
: base(
message: "Local file dependency error occurred, contact support.",
innerException: innerException)
{ }

public LocalFileDependencyException(string message, Xeption innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.LocalFiles.Exceptions
{
internal class LocalFileDependencyValidationException : Xeption
{
public LocalFileDependencyValidationException(Xeption innerException)
: base(
message: "Local file dependency validation error occurred, fix the errors and try again.",
innerException: innerException)
{ }

public LocalFileDependencyValidationException(string message, Xeption innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.LocalFiles.Exceptions
{
public class LocalFileServiceException : Xeption
{
public LocalFileServiceException(Xeption innerException)
: base(
message: "Local file service error occurred, contact support.",
innerException: innerException)
{ }

public LocalFileServiceException(string message, Xeption innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.LocalFiles.Exceptions
{
internal class LocalFileValidationException : Xeption
{
public LocalFileValidationException(Xeption innerException)
: base(
message: "Local file validation error occurred, fix error and try again.",
innerException: innerException)
{ }

public LocalFileValidationException(string message, Xeption innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.LocalFiles.Exceptions
{
internal class NotFoundLocalFileException : Xeption
{
public NotFoundLocalFileException(Exception innerException)
: base(
message: "Not found local file error occurred, fix error and try again.",
innerException: innerException)
{ }

public NotFoundLocalFileException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.IO;
using Standard.AI.OpenAI.Models.Services.Foundations.LocalFiles.Exceptions;
using Xeptions;

namespace Standard.AI.OpenAI.Services.Foundations.LocalFiles
{
Expand All @@ -20,55 +21,105 @@ private Stream TryCatch(ReturningStreamFunction returningStreamFunction)
}
catch (InvalidLocalFileException invalidFileException)
{
throw new LocalFileValidationException(invalidFileException);
throw CreateLocalFileValidationException(invalidFileException);
}
catch (ArgumentException argumentException)
{
var invalidFileException = new InvalidLocalFileException(argumentException);
var invalidFileException =
new InvalidLocalFileException(
message: "Invalid local file error occurred, fix error and try again.",
argumentException);

throw new LocalFileDependencyValidationException(invalidFileException);
throw CreateLocalFileDependencyValidationException(
invalidFileException);
}
catch (PathTooLongException pathTooLongException)
{
var invalidFileException = new InvalidLocalFileException(pathTooLongException);
var invalidFileException =
new InvalidLocalFileException(
message: "Invalid local file error occurred, fix error and try again.",
pathTooLongException);

throw new LocalFileDependencyValidationException(invalidFileException);
throw CreateLocalFileDependencyValidationException(
invalidFileException);
}
catch (FileNotFoundException fileNotFoundException)
{
var notFoundFileException =
new NotFoundLocalFileException(fileNotFoundException);
new NotFoundLocalFileException(
message: "Not found local file error occurred, fix error and try again.",
fileNotFoundException);

throw new LocalFileDependencyValidationException(notFoundFileException);
throw CreateLocalFileDependencyValidationException(
notFoundFileException);
}
catch (DirectoryNotFoundException directoryNotFoundException)
{
var notFoundFileException =
new NotFoundLocalFileException(directoryNotFoundException);
new NotFoundLocalFileException(
message: "Not found local file error occurred, fix error and try again.",
directoryNotFoundException);

throw new LocalFileDependencyValidationException(notFoundFileException);
throw CreateLocalFileDependencyValidationException(
notFoundFileException);
}
catch (IOException ioException)
{
var failedFileException =
new FailedLocalFileDependencyException(ioException);
new FailedLocalFileDependencyException(
message: "Failed local file error occurred, contact support.",
ioException);

throw new LocalFileDependencyException(failedFileException);
throw CreateLocalFileDependencyException(
failedFileException);
}
catch (NotSupportedException notSupportedException)
{
var failedFileException =
new FailedLocalFileDependencyException(notSupportedException);
new FailedLocalFileDependencyException(
message: "Failed local file error occurred, contact support.",
notSupportedException);

throw new LocalFileDependencyException(failedFileException);
throw CreateLocalFileDependencyException(
failedFileException);
}
catch (Exception exception)
{
var failedLocalFileServiceException =
new FailedLocalFileServiceException(exception);
new FailedLocalFileServiceException(
message: "Failed local file service error occurred, contact support.",
exception);

throw new LocalFileServiceException(failedLocalFileServiceException);
throw CreateLocalFileServiceException(failedLocalFileServiceException);
}
}

private static LocalFileValidationException CreateLocalFileValidationException(Xeption innerException)
{
return new LocalFileValidationException(
message: "Local file validation error occurred, fix error and try again.",
innerException);
}
private static LocalFileDependencyValidationException CreateLocalFileDependencyValidationException(
Xeption innerException)
{
return new LocalFileDependencyValidationException(
message: "Local file dependency validation error occurred, fix the errors and try again.",
innerException);
}

private static LocalFileDependencyException CreateLocalFileDependencyException(Xeption innerException)
{
return new LocalFileDependencyException(
message: "Local file dependency error occurred, contact support.",
innerException);
}

private static LocalFileServiceException CreateLocalFileServiceException(Xeption innerException)
{
return new LocalFileServiceException(
message: "Local file service error occurred, contact support.",
innerException);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ private void ValidatePath(string path)

private void Validate(params (dynamic Rule, string Parameter)[] validations)
{
var invalidFileException = new InvalidLocalFileException();
var invalidFileException =
new InvalidLocalFileException(
message: "Invalid local file error occurred, fix error and try again.");

foreach ((dynamic rule, string parameter) in validations)
{
Expand Down

0 comments on commit 1844472

Please sign in to comment.