@@ -131,7 +131,6 @@ impl AsyncSim {
131
131
outpath : PathBuf ,
132
132
) {
133
133
let mut sim_state = initialize ( & config) ;
134
-
135
134
// configure simulation
136
135
let physics_rate = config. environment . tick_rate_hz ;
137
136
let max_sim_time = config. environment . max_elapsed_time_s ;
@@ -187,23 +186,26 @@ impl AsyncSim {
187
186
| sim_state. ascent_rate . is_nan ( )
188
187
| sim_state. acceleration . is_nan ( )
189
188
{
190
- error ! ( "Something went wrong, a physical value is NaN!" ) ;
191
- exit ( 1 ) ;
189
+ terminate ( 1 , format ! ( "Something went wrong, a physical value is NaN!" ) ) ;
192
190
}
193
191
// Run for a certain amount of sim time or to a certain altitude
194
192
if sim_state. time >= max_sim_time {
195
- warn ! ( "Simulation reached maximum time step. Stopping..." ) ;
196
- break ;
193
+ terminate ( 0 , format ! ( "Reached maximum time step ({:?} s)" , sim_state. time) ) ;
197
194
}
198
195
if sim_state. altitude < 0.0 {
199
- error ! ( "Simulation altitude cannot be below zero. Stopping..." ) ;
200
- break ;
196
+ terminate ( 0 , format ! ( "Altitude at or below zero." ) ) ;
201
197
}
202
198
}
203
- exit ( 0 ) ;
204
199
}
205
200
}
206
-
201
+ fn terminate ( code : i32 , reason : String ) {
202
+ if code > 0 {
203
+ error ! ( "Simulation terminated abnormally with code {:?}. Reason: {:?}" , code, reason) ;
204
+ } else {
205
+ warn ! ( "Simulation terminated normally. Reason: {:?}" , reason) ;
206
+ }
207
+ exit ( code) ;
208
+ }
207
209
fn init_log_file ( outpath : PathBuf ) -> csv:: Writer < File > {
208
210
let mut writer = csv:: Writer :: from_path ( outpath) . unwrap ( ) ;
209
211
writer
0 commit comments