@@ -48,17 +48,35 @@ public TResult Deserialize<TResult>()
4848 }
4949}
5050
51- public record Error ( string Message , string StackTrace , string Type , Error ? InnerError )
51+ public record Error ( string Message , string StackTrace , string Type , Error ? InnerError , IReadOnlyDictionary < string , string > ? Data )
5252{
53+ public static readonly HashSet < string > SerializableDataKeys = [ "UiPath.ErrorInfo.Error" ] ;
54+
5355 [ return : NotNullIfNotNull ( "exception" ) ]
5456 public static Error ? FromException ( Exception ? exception )
55- => exception is null
56- ? null
57+ => exception is null
58+ ? null
5759 : new (
58- Message : exception . Message ,
59- StackTrace : exception . StackTrace ?? exception . GetBaseException ( ) . StackTrace ! ,
60- Type : GetExceptionType ( exception ) ,
61- InnerError : FromException ( exception . InnerException ) ) ;
60+ Message : exception . Message ,
61+ StackTrace : exception . StackTrace ?? exception . GetBaseException ( ) . StackTrace ! ,
62+ Type : GetExceptionType ( exception ) ,
63+ InnerError : FromException ( exception . InnerException ) ,
64+ Data : GetExceptionData ( exception ) ) ;
65+
66+ private static IReadOnlyDictionary < string , string > ? GetExceptionData ( Exception exception )
67+ {
68+ Dictionary < string , string > ? data = null ;
69+ foreach ( var key in SerializableDataKeys )
70+ {
71+ if ( exception . Data . Contains ( key ) )
72+ {
73+ data ??= [ ] ;
74+ data [ key ] = IpcJsonSerializer . Instance . Serialize ( exception . Data [ key ] ) ;
75+ }
76+ }
77+ return data ;
78+ }
79+
6280 public override string ToString ( ) => new RemoteException ( this ) . ToString ( ) ;
6381
6482 private static string GetExceptionType ( Exception exception ) => ( exception as RemoteException ) ? . Type ?? exception . GetType ( ) . FullName ! ;
@@ -70,6 +88,13 @@ public class RemoteException : Exception
7088 {
7189 Type = error . Type ;
7290 StackTrace = error . StackTrace ;
91+ if ( error . Data != null )
92+ {
93+ foreach ( var key in error . Data )
94+ {
95+ Data [ key . Key ] = IpcJsonSerializer . Instance . Deserialize ( key . Value , typeof ( object ) ) ;
96+ }
97+ }
7398 }
7499 public string Type { get ; }
75100 public override string StackTrace { get ; }
0 commit comments