22
33// Copyright (c) 2014 The Sentry Team and individual contributors.
44// All rights reserved.
5- //
5+ //
66// Redistribution and use in source and binary forms, with or without modification, are permitted
77// provided that the following conditions are met:
8- //
8+ //
99// 1. Redistributions of source code must retain the above copyright notice, this list of
1010// conditions and the following disclaimer.
11- //
11+ //
1212// 2. Redistributions in binary form must reproduce the above copyright notice, this list of
1313// conditions and the following disclaimer in the documentation and/or other materials
1414// provided with the distribution.
15- //
15+ //
1616// 3. Neither the name of the Sentry nor the names of its contributors may be used to
1717// endorse or promote products derived from this software without specific prior written
1818// permission.
19- //
19+ //
2020// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
2121// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
2222// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
@@ -55,46 +55,24 @@ public JsonPacket(string project, Exception exception)
5555 if ( exception == null )
5656 throw new ArgumentNullException ( "exception" ) ;
5757
58- Message = exception . Message ;
59-
60- if ( exception . TargetSite != null )
61- {
62- // ReSharper disable ConditionIsAlwaysTrueOrFalse => not for dynamic types.
63- Culprit = String . Format ( "{0} in {1}" ,
64- ( ( exception . TargetSite . ReflectedType == null )
65- ? "<dynamic type>"
66- : exception . TargetSite . ReflectedType . FullName ) ,
67- exception . TargetSite . Name ) ;
68- // ReSharper restore ConditionIsAlwaysTrueOrFalse
69- }
70-
71- Exceptions = new List < SentryException > ( ) ;
58+ Initialize ( exception ) ;
59+ }
7260
73- for ( Exception currentException = exception ;
74- currentException != null ;
75- currentException = currentException . InnerException )
76- {
77- SentryException sentryException = new SentryException ( currentException )
78- {
79- Module = currentException . Source ,
80- Type = currentException . GetType ( ) . Name ,
81- Value = currentException . Message
82- } ;
8361
84- Exceptions . Add ( sentryException ) ;
85- }
62+ /// <summary>Initializes a new instance of the <see cref="JsonPacket"/> class.</summary>
63+ /// <param name="project">The project.</param>
64+ /// <param name="event">The event.</param>
65+ public JsonPacket ( string project , SentryEvent @event )
66+ : this ( project )
67+ {
68+ if ( @event == null )
69+ throw new ArgumentNullException ( "event" ) ;
8670
87- // ReflectionTypeLoadException doesn't contain much useful info in itself, and needs special handling
88- ReflectionTypeLoadException reflectionTypeLoadException = exception as ReflectionTypeLoadException ;
89- if ( reflectionTypeLoadException != null )
90- {
91- foreach ( Exception loaderException in reflectionTypeLoadException . LoaderExceptions )
92- {
93- SentryException sentryException = new SentryException ( loaderException ) ;
71+ if ( @event . Exception != null )
72+ Initialize ( @event . Exception ) ;
9473
95- Exceptions . Add ( sentryException ) ;
96- }
97- }
74+ Message = @event . Message != null ? @event . Message . ToString ( ) : null ;
75+ MessageObject = @event . Message ;
9876 }
9977
10078
@@ -156,6 +134,12 @@ private JsonPacket()
156134 [ JsonProperty ( PropertyName = "culprit" , NullValueHandling = NullValueHandling . Ignore ) ]
157135 public string Culprit { get ; set ; }
158136
137+ /// <summary>
138+ /// Identifies the operating environment (e.g. production).
139+ /// </summary>
140+ [ JsonProperty ( PropertyName = "environment" , NullValueHandling = NullValueHandling . Ignore ) ]
141+ public string Environment { get ; set ; }
142+
159143 /// <summary>
160144 /// Hexadecimal string representing a uuid4 value.
161145 /// </summary>
@@ -177,6 +161,12 @@ private JsonPacket()
177161 [ JsonProperty ( PropertyName = "extra" , NullValueHandling = NullValueHandling . Ignore ) ]
178162 public object Extra { get ; set ; }
179163
164+ /// <summary>
165+ /// Gets or sets the fingerprint used for custom grouping
166+ /// </summary>
167+ [ JsonProperty ( PropertyName = "fingerprint" , NullValueHandling = NullValueHandling . Ignore ) ]
168+ public string [ ] Fingerprint { get ; set ; }
169+
180170 /// <summary>
181171 /// The record severity.
182172 /// Defaults to error.
@@ -250,18 +240,6 @@ private JsonPacket()
250240 [ JsonProperty ( PropertyName = "server_name" , NullValueHandling = NullValueHandling . Ignore ) ]
251241 public string ServerName { get ; set ; }
252242
253- /// <summary>
254- /// Gets or sets the fingerprint used for custom grouping
255- /// </summary>
256- [ JsonProperty ( PropertyName = "fingerprint" , NullValueHandling = NullValueHandling . Ignore ) ]
257- public string [ ] Fingerprint { get ; set ; }
258-
259- /// <summary>
260- /// Identifies the operating environment (e.g. production).
261- /// </summary>
262- [ JsonProperty ( PropertyName = "environment" , NullValueHandling = NullValueHandling . Ignore ) ]
263- public string Environment { get ; set ; }
264-
265243 /// <summary>
266244 /// A map or list of tags for this event.
267245 /// </summary>
@@ -308,5 +286,50 @@ public override string ToString()
308286 {
309287 return JsonConvert . SerializeObject ( this ) ;
310288 }
289+
290+
291+ private void Initialize ( Exception exception )
292+ {
293+ Message = exception . Message ;
294+
295+ if ( exception . TargetSite != null )
296+ {
297+ // ReSharper disable ConditionIsAlwaysTrueOrFalse => not for dynamic types.
298+ Culprit = String . Format ( "{0} in {1}" ,
299+ ( ( exception . TargetSite . ReflectedType == null )
300+ ? "<dynamic type>"
301+ : exception . TargetSite . ReflectedType . FullName ) ,
302+ exception . TargetSite . Name ) ;
303+ // ReSharper restore ConditionIsAlwaysTrueOrFalse
304+ }
305+
306+ Exceptions = new List < SentryException > ( ) ;
307+
308+ for ( Exception currentException = exception ;
309+ currentException != null ;
310+ currentException = currentException . InnerException )
311+ {
312+ SentryException sentryException = new SentryException ( currentException )
313+ {
314+ Module = currentException . Source ,
315+ Type = currentException . GetType ( ) . Name ,
316+ Value = currentException . Message
317+ } ;
318+
319+ Exceptions . Add ( sentryException ) ;
320+ }
321+
322+ // ReflectionTypeLoadException doesn't contain much useful info in itself, and needs special handling
323+ ReflectionTypeLoadException reflectionTypeLoadException = exception as ReflectionTypeLoadException ;
324+ if ( reflectionTypeLoadException != null )
325+ {
326+ foreach ( Exception loaderException in reflectionTypeLoadException . LoaderExceptions )
327+ {
328+ SentryException sentryException = new SentryException ( loaderException ) ;
329+
330+ Exceptions . Add ( sentryException ) ;
331+ }
332+ }
333+ }
311334 }
312- }
335+ }
0 commit comments