1919
2020using  System . Collections . Generic ; 
2121
22+ #nullable enable
23+ 
2224namespace  OpenQA . Selenium 
2325{ 
2426    /// <summary> 
2527    /// Provides a way to store errors from a response 
2628    /// </summary> 
2729    public  class  ErrorResponse 
2830    { 
29-         private  StackTraceElement [ ]  stackTrace ; 
30-         private  string  message  =  string . Empty ; 
31-         private  string  className  =  string . Empty ; 
32-         private  string  screenshot  =  string . Empty ; 
33- 
3431        /// <summary> 
3532        /// Initializes a new instance of the <see cref="ErrorResponse"/> class. 
3633        /// </summary> 
@@ -43,58 +40,45 @@ public ErrorResponse()
4340        /// </summary> 
4441        /// <param name="responseValue">A <see cref="Dictionary{K, V}"/> containing names and values of 
4542        /// the properties of this <see cref="ErrorResponse"/>.</param> 
46-         public  ErrorResponse ( Dictionary < string ,  object >  responseValue ) 
43+         public  ErrorResponse ( Dictionary < string ,  object ? > ?  responseValue ) 
4744        { 
4845            if  ( responseValue  !=  null ) 
4946            { 
50-                 if  ( responseValue . ContainsKey ( "message" ) ) 
47+                 if  ( responseValue . TryGetValue ( "message" ,  out  object ?  messageObj ) 
48+                     &&  messageObj ? . ToString ( )  is  string  message ) 
5149                { 
52-                     if  ( responseValue [ "message" ]  !=  null ) 
53-                     { 
54-                         this . message  =  responseValue [ "message" ] . ToString ( ) ; 
55-                     } 
56-                     else 
57-                     { 
58-                         this . message  =  "The error did not contain a message." ; 
59-                     } 
50+                     this . Message  =  message ; 
6051                } 
61- 
62-                 if  ( responseValue . ContainsKey ( "screen" )  &&  responseValue [ "screen" ]  !=  null ) 
52+                 else 
6353                { 
64-                     this . screenshot  =  responseValue [ "screen" ] . ToString ( ) ; 
54+                     this . Message  =  "The error did not contain a message." ; 
6555                } 
6656
67-                 if  ( responseValue . ContainsKey ( "class" )   &&   responseValue [ "class" ]   !=   null ) 
57+                 if  ( responseValue . TryGetValue ( "screen" ,   out   object ?   screenObj ) ) 
6858                { 
69-                     this . className  =  responseValue [ "class" ] . ToString ( ) ; 
59+                     this . Screenshot  =  screenObj ? . ToString ( ) ; 
7060                } 
7161
72-                 if  ( responseValue . ContainsKey ( "stackTrace" )   ||   responseValue . ContainsKey ( "stacktrace" ) ) 
62+                 if  ( responseValue . TryGetValue ( "class" ,   out   object ?   classObj ) ) 
7363                { 
74-                     object [ ]  stackTraceArray  =  null ; 
75- 
76-                     if  ( responseValue . ContainsKey ( "stackTrace" ) ) 
77-                     { 
78-                         stackTraceArray  =  responseValue [ "stackTrace" ]  as  object [ ] ; 
79-                     } 
80-                     else  if  ( responseValue . ContainsKey ( "stacktrace" ) ) 
81-                     { 
82-                         stackTraceArray  =  responseValue [ "stacktrace" ]  as  object [ ] ; 
83-                     } 
64+                     this . ClassName  =  classObj ? . ToString ( ) ; 
65+                 } 
8466
85-                     if  ( stackTraceArray  !=  null ) 
67+                 if  ( responseValue . TryGetValue ( "stackTrace" ,  out  object ?  stackTraceObj ) 
68+                     ||  responseValue . TryGetValue ( "stacktrace" ,  out  stackTraceObj ) ) 
69+                 { 
70+                     if  ( stackTraceObj  is  object ? [ ]  stackTraceArray ) 
8671                    { 
8772                        List < StackTraceElement >  stackTraceList  =  new  List < StackTraceElement > ( ) ; 
88-                         foreach  ( object  rawStackTraceElement  in  stackTraceArray ) 
73+                         foreach  ( object ?  rawStackTraceElement  in  stackTraceArray ) 
8974                        { 
90-                             Dictionary < string ,  object >  elementAsDictionary  =  rawStackTraceElement  as  Dictionary < string ,  object > ; 
91-                             if  ( elementAsDictionary  !=  null ) 
75+                             if  ( rawStackTraceElement  is  Dictionary < string ,  object ? >  elementAsDictionary ) 
9276                            { 
9377                                stackTraceList . Add ( new  StackTraceElement ( elementAsDictionary ) ) ; 
9478                            } 
9579                        } 
9680
97-                         this . stackTrace  =  stackTraceList . ToArray ( ) ; 
81+                         this . StackTrace  =  stackTraceList . ToArray ( ) ; 
9882                    } 
9983                } 
10084            } 
@@ -103,38 +87,22 @@ public ErrorResponse(Dictionary<string, object> responseValue)
10387        /// <summary> 
10488        /// Gets or sets the message from the response 
10589        /// </summary> 
106-         public  string  Message 
107-         { 
108-             get  {  return  this . message ;  } 
109-             set  {  this . message  =  value ;  } 
110-         } 
90+         public  string  Message  {  get ;  }  =  string . Empty ; 
11191
11292        /// <summary> 
11393        /// Gets or sets the class name that threw the error 
11494        /// </summary> 
115-         public  string  ClassName 
116-         { 
117-             get  {  return  this . className ;  } 
118-             set  {  this . className  =  value ;  } 
119-         } 
95+         public  string ?  ClassName  {  get ;  } 
12096
97+         // TODO: (JimEvans) Change this to return an Image. 
12198        /// <summary> 
12299        /// Gets or sets the screenshot of the error 
123100        /// </summary> 
124-         public  string  Screenshot 
125-         { 
126-             // TODO: (JimEvans) Change this to return an Image. 
127-             get  {  return  this . screenshot ;  } 
128-             set  {  this . screenshot  =  value ;  } 
129-         } 
101+         public  string ?  Screenshot  {  get ;  } 
130102
131103        /// <summary> 
132104        /// Gets or sets the stack trace of the error 
133105        /// </summary> 
134-         public  StackTraceElement [ ]  StackTrace 
135-         { 
136-             get  {  return  this . stackTrace ;  } 
137-             set  {  this . stackTrace  =  value ;  } 
138-         } 
106+         public  StackTraceElement [ ] ?  StackTrace  {  get ;  } 
139107    } 
140108} 
0 commit comments