From 9fe372cdd3ab6fdc42e326de08347ab7539df4b9 Mon Sep 17 00:00:00 2001 From: Lucian Bargaoanu Date: Sun, 2 Oct 2022 08:38:22 +0300 Subject: [PATCH] cosmetic --- src/UiPath.CoreIpc.Tests/ValidationTests.cs | 4 ++-- src/UiPath.CoreIpc/Dtos.cs | 5 +---- src/UiPath.CoreIpc/Helpers.cs | 2 ++ 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/UiPath.CoreIpc.Tests/ValidationTests.cs b/src/UiPath.CoreIpc.Tests/ValidationTests.cs index 6f59c2c6..a1a0197c 100644 --- a/src/UiPath.CoreIpc.Tests/ValidationTests.cs +++ b/src/UiPath.CoreIpc.Tests/ValidationTests.cs @@ -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); diff --git a/src/UiPath.CoreIpc/Dtos.cs b/src/UiPath.CoreIpc/Dtos.cs index 0f0badcf..cbf278ba 100644 --- a/src/UiPath.CoreIpc/Dtos.cs +++ b/src/UiPath.CoreIpc/Dtos.cs @@ -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(ISerializer serializer, bool objectParameters) @@ -45,10 +45,7 @@ public TResult Deserialize(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 diff --git a/src/UiPath.CoreIpc/Helpers.cs b/src/UiPath.CoreIpc/Helpers.cs index 9805058d..022020fb 100644 --- a/src/UiPath.CoreIpc/Helpers.cs +++ b/src/UiPath.CoreIpc/Helpers.cs @@ -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) =>