@@ -48,17 +48,35 @@ public TResult Deserialize<TResult>()
48
48
}
49
49
}
50
50
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 )
52
52
{
53
+ public static readonly HashSet < string > SerializableDataKeys = [ "UiPath.ErrorInfo.Error" ] ;
54
+
53
55
[ return : NotNullIfNotNull ( "exception" ) ]
54
56
public static Error ? FromException ( Exception ? exception )
55
- => exception is null
56
- ? null
57
+ => exception is null
58
+ ? null
57
59
: 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
+
62
80
public override string ToString ( ) => new RemoteException ( this ) . ToString ( ) ;
63
81
64
82
private static string GetExceptionType ( Exception exception ) => ( exception as RemoteException ) ? . Type ?? exception . GetType ( ) . FullName ! ;
@@ -70,6 +88,13 @@ public class RemoteException : Exception
70
88
{
71
89
Type = error . Type ;
72
90
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
+ }
73
98
}
74
99
public string Type { get ; }
75
100
public override string StackTrace { get ; }
0 commit comments