From fd941cc6918be75b6ba03d2886d7efcfcfec3efb Mon Sep 17 00:00:00 2001 From: Tyler Date: Thu, 10 Feb 2022 16:41:49 -0600 Subject: [PATCH 01/10] replaces unwraps with expects in bevy_app --- crates/bevy_app/src/schedule_runner.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/bevy_app/src/schedule_runner.rs b/crates/bevy_app/src/schedule_runner.rs index 3227826f70d06..c9d4b4480ebf8 100644 --- a/crates/bevy_app/src/schedule_runner.rs +++ b/crates/bevy_app/src/schedule_runner.rs @@ -123,7 +123,7 @@ impl Plugin for ScheduleRunnerPlugin { { fn set_timeout(f: &Closure, dur: Duration) { web_sys::window() - .unwrap() + .expect("Could not get window.") .set_timeout_with_callback_and_timeout_and_arguments_0( f.as_ref().unchecked_ref(), dur.as_millis() as i32, @@ -140,14 +140,22 @@ impl Plugin for ScheduleRunnerPlugin { let mut app = Rc::get_mut(&mut rc).unwrap(); let delay = tick(&mut app, wait); match delay { - Ok(delay) => { - set_timeout(f.borrow().as_ref().unwrap(), delay.unwrap_or(asap)) - } + Ok(delay) => set_timeout( + f.borrow() + .as_ref() + .expect("No closure was found for set_timeout."), + delay.unwrap_or(asap), + ), Err(_) => {} } }; *g.borrow_mut() = Some(Closure::wrap(Box::new(c) as Box)); - set_timeout(g.borrow().as_ref().unwrap(), asap); + set_timeout( + g.borrow() + .as_ref() + .expect("No closure was found for set_timeout."), + asap, + ); }; } } From 8def88638823d6712d1bf277d39c713e6c5486ff Mon Sep 17 00:00:00 2001 From: Tyler Date: Thu, 10 Feb 2022 16:53:41 -0600 Subject: [PATCH 02/10] replaces unwraps with expects in bevy_audio --- crates/bevy_audio/src/audio_output.rs | 15 +++++++++++---- crates/bevy_audio/src/audio_source.rs | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/bevy_audio/src/audio_output.rs b/crates/bevy_audio/src/audio_output.rs index 385b7d5fdc580..d121431bc9b6b 100644 --- a/crates/bevy_audio/src/audio_output.rs +++ b/crates/bevy_audio/src/audio_output.rs @@ -43,7 +43,8 @@ where { fn play_source(&self, audio_source: &Source) { if let Some(stream_handle) = &self.stream_handle { - let sink = Sink::try_new(stream_handle).unwrap(); + let sink = + Sink::try_new(stream_handle).expect("Could not create Sink from stream_handle."); sink.append(audio_source.decoder()); sink.detach(); } @@ -54,7 +55,9 @@ where let len = queue.len(); let mut i = 0; while i < len { - let audio_source_handle = queue.pop_back().unwrap(); + let audio_source_handle = queue + .pop_back() + .expect("Could not find anything in the queue."); if let Some(audio_source) = audio_sources.get(&audio_source_handle) { self.play_source(audio_source); } else { @@ -72,8 +75,12 @@ where Source: Decodable, { let world = world.cell(); - let audio_output = world.get_non_send::>().unwrap(); - let mut audio = world.get_resource_mut::>().unwrap(); + let audio_output = world + .get_non_send::>() + .expect("Could not find `AudioOutput` in the `World`."); + let mut audio = world + .get_resource_mut::>() + .expect("Could not find `Audio` in the `World`."); if let Some(audio_sources) = world.get_resource::>() { audio_output.try_play_queued(&*audio_sources, &mut *audio); diff --git a/crates/bevy_audio/src/audio_source.rs b/crates/bevy_audio/src/audio_source.rs index 823526046c7c3..3ad078fec0a2a 100644 --- a/crates/bevy_audio/src/audio_source.rs +++ b/crates/bevy_audio/src/audio_source.rs @@ -67,6 +67,6 @@ impl Decodable for AudioSource { type DecoderItem = > as Iterator>::Item; fn decoder(&self) -> Self::Decoder { - rodio::Decoder::new(Cursor::new(self.clone())).unwrap() + rodio::Decoder::new(Cursor::new(self.clone())).expect("Could not create `Decoder`.") } } From a04e8a1355328b547356b837e6f4c32a51b90363 Mon Sep 17 00:00:00 2001 From: Tyler Date: Thu, 10 Feb 2022 17:06:38 -0600 Subject: [PATCH 03/10] replaces unwraps with expects in bevy_core --- crates/bevy_core/src/time/fixed_timestep.rs | 48 +++++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/crates/bevy_core/src/time/fixed_timestep.rs b/crates/bevy_core/src/time/fixed_timestep.rs index 7b773cbc69caa..7fabd764ff906 100644 --- a/crates/bevy_core/src/time/fixed_timestep.rs +++ b/crates/bevy_core/src/time/fixed_timestep.rs @@ -121,7 +121,10 @@ impl FixedTimestep { ) -> ShouldRun { let should_run = state.update(&time); if let Some(ref label) = state.label { - let res_state = fixed_timesteps.fixed_timesteps.get_mut(label).unwrap(); + let res_state = fixed_timesteps + .fixed_timesteps + .get_mut(label) + .expect("Could not find fixed_timesteps"); res_state.step = state.step; res_state.accumulator = state.accumulator; } @@ -205,7 +208,9 @@ impl System for FixedTimestep { Box::new(Self::prepare_system.config(|c| c.0 = Some(self.state.clone()))); self.internal_system.initialize(world); if let Some(ref label) = self.state.label { - let mut fixed_timesteps = world.get_resource_mut::().unwrap(); + let mut fixed_timesteps = world + .get_resource_mut::() + .expect("Could not find `FixedTimesteps` in the `World`."); fixed_timesteps.fixed_timesteps.insert( label.clone(), FixedTimestepState { @@ -253,25 +258,45 @@ mod test { // if time does not progress, the step does not run schedule.run(&mut world); schedule.run(&mut world); - assert_eq!(0, *world.get_resource::().unwrap()); + assert_eq!( + 0, + *world + .get_resource::() + .expect("Could not find `Count` in the `World`.") + ); assert_eq!(0., get_accumulator_deciseconds(&world)); // let's progress less than one step advance_time(&mut world, instance, 0.4); schedule.run(&mut world); - assert_eq!(0, *world.get_resource::().unwrap()); + assert_eq!( + 0, + *world + .get_resource::() + .expect("Could not find `Count` in the `World`.") + ); assert_eq!(4., get_accumulator_deciseconds(&world)); // finish the first step with 0.1s above the step length advance_time(&mut world, instance, 0.6); schedule.run(&mut world); - assert_eq!(1, *world.get_resource::().unwrap()); + assert_eq!( + 1, + *world + .get_resource::() + .expect("Could not find `Count` in the `World`.") + ); assert_eq!(1., get_accumulator_deciseconds(&world)); // runs multiple times if the delta is multiple step lengths advance_time(&mut world, instance, 1.7); schedule.run(&mut world); - assert_eq!(3, *world.get_resource::().unwrap()); + assert_eq!( + 3, + *world + .get_resource::() + .expect("Could not find `Count` in the `World`.") + ); assert_eq!(2., get_accumulator_deciseconds(&world)); } @@ -282,16 +307,21 @@ mod test { fn advance_time(world: &mut World, instance: Instant, seconds: f32) { world .get_resource_mut::