1
1
using System . Diagnostics . CodeAnalysis ;
2
2
using System . Text ;
3
3
using Newtonsoft . Json ;
4
+ using Newtonsoft . Json . Linq ;
4
5
5
6
namespace UiPath . Ipc ;
6
7
@@ -48,17 +49,40 @@ public TResult Deserialize<TResult>()
48
49
}
49
50
}
50
51
51
- public record Error ( string Message , string StackTrace , string Type , Error ? InnerError )
52
+ public record Error ( string Message , string StackTrace , string Type , Error ? InnerError , IReadOnlyDictionary < string , object ? > ? Data )
52
53
{
54
+ public static readonly HashSet < string > SerializableDataKeys = [ "UiPath.ErrorInfo.Error" ] ;
55
+
53
56
[ return : NotNullIfNotNull ( "exception" ) ]
54
57
public static Error ? FromException ( Exception ? exception )
55
- => exception is null
56
- ? null
58
+ => exception is null
59
+ ? null
57
60
: new (
58
- Message : exception . Message ,
59
- StackTrace : exception . StackTrace ?? exception . GetBaseException ( ) . StackTrace ! ,
60
- Type : GetExceptionType ( exception ) ,
61
- InnerError : FromException ( exception . InnerException ) ) ;
61
+ Message : exception . Message ,
62
+ StackTrace : exception . StackTrace ?? exception . GetBaseException ( ) . StackTrace ! ,
63
+ Type : GetExceptionType ( exception ) ,
64
+ InnerError : FromException ( exception . InnerException ) ,
65
+ Data : GetExceptionData ( exception ) ) ;
66
+
67
+ private static IReadOnlyDictionary < string , object ? > ? GetExceptionData ( Exception exception )
68
+ {
69
+ Dictionary < string , object ? > ? data = null ;
70
+ foreach ( var key in SerializableDataKeys )
71
+ {
72
+ if ( exception . Data . Contains ( key ) )
73
+ {
74
+ data ??= [ ] ;
75
+ var value = exception . Data [ key ] ;
76
+ data [ key ] = value switch
77
+ {
78
+ null or string or int or bool or Int64 or double or decimal or float => value ,
79
+ _ => JToken . FromObject ( value , IpcJsonSerializer . StringArgsSerializer )
80
+ } ;
81
+ }
82
+ }
83
+ return data ;
84
+ }
85
+
62
86
public override string ToString ( ) => new RemoteException ( this ) . ToString ( ) ;
63
87
64
88
private static string GetExceptionType ( Exception exception ) => ( exception as RemoteException ) ? . Type ?? exception . GetType ( ) . FullName ! ;
@@ -70,6 +94,14 @@ public class RemoteException : Exception
70
94
{
71
95
Type = error . Type ;
72
96
StackTrace = error . StackTrace ;
97
+ if ( error . Data != null )
98
+ {
99
+ foreach ( var key in error . Data )
100
+ {
101
+ var value = key . Value ;
102
+ Data [ key . Key ] = value ;
103
+ }
104
+ }
73
105
}
74
106
public string Type { get ; }
75
107
public override string StackTrace { get ; }
0 commit comments