@@ -2,7 +2,7 @@ use crate::channel::EventChannel;
22use crate :: deeplink_bridge:: {
33 PlaceDeeplinkError , PlaceDeeplinkResult , place_deeplink_and_wait_until_consumed,
44} ;
5- use crate :: errors:: { StepError , StepResultTyped } ;
5+ use crate :: errors:: { AttemptError , StepError , StepResultTyped } ;
66use crate :: instances:: RunningInstances ;
77use crate :: protocols:: Protocol ;
88use crate :: {
@@ -73,6 +73,8 @@ pub struct LaunchFlow {
7373 download_step : DownloadStep ,
7474 install_step : InstallStep ,
7575 app_launch_step : AppLaunchStep ,
76+
77+ analytics : Arc < Mutex < Analytics > > ,
7678}
7779
7880impl LaunchFlow {
@@ -87,12 +89,15 @@ impl LaunchFlow {
8789 download_step : DownloadStep {
8890 analytics : analytics. clone ( ) ,
8991 } ,
90- install_step : InstallStep { analytics } ,
92+ install_step : InstallStep {
93+ analytics : analytics. clone ( ) ,
94+ } ,
9195 app_launch_step : AppLaunchStep {
9296 installs_hub,
9397 running_instances,
9498 protocol,
9599 } ,
100+ analytics,
96101 }
97102 }
98103
@@ -101,17 +106,43 @@ impl LaunchFlow {
101106 channel : & T ,
102107 state : Arc < Mutex < LaunchFlowState > > ,
103108 ) -> std:: result:: Result < ( ) , FlowError > {
104- let result = self . launch_internal ( channel, state. clone ( ) ) . await ;
105- if let Err ( e) = result {
106- log:: error!( "Error during the flow {} {:#?}" , e, e) ;
107- sentry:: capture_error ( & e) ;
109+ const SILENT_ATTEMPTS_COUNT : u8 = 3 ;
110+
111+ let mut last_error: Option < AttemptError > = None ;
112+
113+ for attempt in 1 ..=SILENT_ATTEMPTS_COUNT {
114+ let result = self . launch_internal ( channel, state. clone ( ) ) . await ;
115+
116+ if let Err ( e) = result {
117+ log:: error!(
118+ "Error during the flow. Attempt: {}, Cause {} {:#?}" ,
119+ attempt,
120+ e,
121+ e
122+ ) ;
123+ let e = AttemptError {
124+ error : e,
125+ attempt,
126+ } ;
127+
128+ sentry:: capture_error ( & e) ;
129+ self . analytics . lock ( ) . await . track_and_flush_silent ( ( & e) . into ( ) ) . await ;
130+
131+ last_error = Some ( e) ;
132+ continue ;
133+ }
134+
135+ return std:: result:: Result :: Ok ( ( ) ) ;
136+ }
137+
138+ if let Some ( e) = last_error {
108139 let error = FlowError {
109- user_message : e. user_message ( ) . to_owned ( ) ,
140+ user_message : e. error . user_message ( ) . to_owned ( ) ,
110141 } ;
111- return std:: result:: Result :: Err ( error) ;
142+ std:: result:: Result :: Err ( error)
143+ } else {
144+ std:: result:: Result :: Ok ( ( ) )
112145 }
113-
114- std:: result:: Result :: Ok ( ( ) )
115146 }
116147
117148 async fn launch_internal < T : EventChannel > (
0 commit comments