Skip to content

Commit

Permalink
cosmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
lbargaoanu committed Oct 2, 2022
1 parent 765b8cb commit 9fe372c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/UiPath.CoreIpc.Tests/ValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class JobFailedException : Exception
[Fact]
public void ErrorFromRemoteException()
{
var innerError = Error.FromException(new InvalidDataException("invalid"));
var error = Error.FromException(new JobFailedException(innerError));
var innerError = new InvalidDataException("invalid").ToError();
var error = new JobFailedException(innerError).ToError();
error.Type.ShouldBe(typeof(JobFailedException).FullName);
error.Message.ShouldBe("Job has failed.");
error.InnerError.Type.ShouldBe(typeof(InvalidDataException).FullName);
Expand Down
5 changes: 1 addition & 4 deletions src/UiPath.CoreIpc/Dtos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ record CancellationRequest(string RequestId);
record Response(string RequestId, string Data = null, object ObjectData = null, Error Error = null)
{
internal Stream DownloadStream { get; set; }
public static Response Fail(Request request, Exception ex) => new(request.Id, Error: Error.FromException(ex));
public static Response Fail(Request request, Exception ex) => new(request.Id, Error: ex.ToError());
public static Response Success(Request request, string data) => new(request.Id, data);
public static Response Success(Request request, Stream downloadStream) => new(request.Id) { DownloadStream = downloadStream };
public TResult Deserialize<TResult>(ISerializer serializer, bool objectParameters)
Expand All @@ -45,10 +45,7 @@ public TResult Deserialize<TResult>(ISerializer serializer, bool objectParameter
[Serializable]
public record Error(string Message, string StackTrace, string Type, Error InnerError)
{
public static Error FromException(Exception ex) => new(ex.Message, ex.StackTrace ?? ex.GetBaseException().StackTrace, GetExceptionType(ex),
ex.InnerException == null ? null : FromException(ex.InnerException));
public override string ToString() => new RemoteException(this).ToString();
private static string GetExceptionType(Exception exception) => (exception as RemoteException)?.Type ?? exception.GetType().FullName;
}
[Serializable]
public class RemoteException : Exception
Expand Down
2 changes: 2 additions & 0 deletions src/UiPath.CoreIpc/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public static async Task ConnectAsync(this TcpClient tcpClient, IPAddress addres
await tcpClient.ConnectAsync(address, port);
}
#endif
public static Error ToError(this Exception ex) => new(ex.Message, ex.StackTrace ?? ex.GetBaseException().StackTrace, GetExceptionType(ex), ex.InnerException?.ToError());
private static string GetExceptionType(Exception exception) => (exception as RemoteException)?.Type ?? exception.GetType().FullName;
public static bool Enabled(this ILogger logger) => logger != null && logger.IsEnabled(LogLevel.Information);
[Conditional("DEBUG")]
public static void AssertDisposed(this SemaphoreSlim semaphore) =>
Expand Down

0 comments on commit 9fe372c

Please sign in to comment.