Skip to content

Commit 0b24d6d

Browse files
committed
friendlier termination logs
1 parent d0faabb commit 0b24d6d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/simulator/mod.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ impl AsyncSim {
131131
outpath: PathBuf,
132132
) {
133133
let mut sim_state = initialize(&config);
134-
135134
// configure simulation
136135
let physics_rate = config.environment.tick_rate_hz;
137136
let max_sim_time = config.environment.max_elapsed_time_s;
@@ -187,23 +186,26 @@ impl AsyncSim {
187186
| sim_state.ascent_rate.is_nan()
188187
| sim_state.acceleration.is_nan()
189188
{
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!"));
192190
}
193191
// Run for a certain amount of sim time or to a certain altitude
194192
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));
197194
}
198195
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."));
201197
}
202198
}
203-
exit(0);
204199
}
205200
}
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+
}
207209
fn init_log_file(outpath: PathBuf) -> csv::Writer<File> {
208210
let mut writer = csv::Writer::from_path(outpath).unwrap();
209211
writer

0 commit comments

Comments
 (0)