22// SPDX-License-Identifier: Apache-2.0
33use std:: { fmt:: Write , time:: SystemTime } ;
44
5- use crate :: SigInfo ;
5+ use crate :: { ErrorKind , SigInfo } ;
66
77use super :: { CrashInfo , Metadata } ;
88use anyhow:: Context ;
@@ -26,6 +26,7 @@ struct TelemetryMetadata {
2626pub struct CrashPingBuilder {
2727 crash_uuid : Uuid ,
2828 custom_message : Option < String > ,
29+ kind : Option < ErrorKind > ,
2930 metadata : Option < Metadata > ,
3031 sig_info : Option < SigInfo > ,
3132}
@@ -38,6 +39,7 @@ impl CrashPingBuilder {
3839 Self {
3940 crash_uuid,
4041 custom_message : None ,
42+ kind : None ,
4143 metadata : None ,
4244 sig_info : None ,
4345 }
@@ -53,6 +55,11 @@ impl CrashPingBuilder {
5355 self
5456 }
5557
58+ pub fn with_kind ( mut self , kind : ErrorKind ) -> Self {
59+ self . kind = Some ( kind) ;
60+ self
61+ }
62+
5663 pub fn with_metadata ( mut self , metadata : Metadata ) -> Self {
5764 self . metadata = Some ( metadata) ;
5865 self
@@ -62,6 +69,7 @@ impl CrashPingBuilder {
6269 let crash_uuid = self . crash_uuid ;
6370 let sig_info = self . sig_info ;
6471 let metadata = self . metadata . context ( "metadata is required" ) ?;
72+ let kind = self . kind . context ( "kind is required" ) ?;
6573
6674 let message = if let Some ( custom_message) = self . custom_message {
6775 format ! ( "Crashtracker crash ping: crash processing started - {custom_message}" )
@@ -71,13 +79,13 @@ impl CrashPingBuilder {
7179 sig_info. si_code_human_readable, sig_info. si_signo_human_readable
7280 )
7381 } else {
74- "Crashtracker crash ping: crash processing started - Process terminated" . to_string ( )
82+ format ! ( "Crashtracker crash ping: crash processing started - Process terminated due to {:?}" , kind )
7583 } ;
7684
7785 Ok ( CrashPing {
7886 crash_uuid : crash_uuid. to_string ( ) ,
79- kind : "Crash ping" . to_string ( ) ,
8087 message,
88+ kind,
8189 metadata,
8290 siginfo : sig_info,
8391 version : CrashPing :: current_schema_version ( ) ,
@@ -88,11 +96,11 @@ impl CrashPingBuilder {
8896#[ derive( Debug , Serialize ) ]
8997pub struct CrashPing {
9098 crash_uuid : String ,
99+ kind : ErrorKind ,
100+ message : String ,
91101 #[ serde( skip_serializing_if = "Option::is_none" ) ]
92102 siginfo : Option < SigInfo > ,
93- message : String ,
94103 version : String ,
95- kind : String ,
96104 metadata : Metadata ,
97105}
98106
0 commit comments