Skip to content

Commit fa18a5d

Browse files
committed
Fix errors and panics to typical Rust conventions
1 parent f54eb12 commit fa18a5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+171
-161
lines changed

crates/bevy_app/src/plugin_group.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ impl PluginGroupBuilder {
3838
.find(|(_i, ty)| **ty == TypeId::of::<Target>())
3939
.map(|(i, _)| i)
4040
.unwrap_or_else(|| {
41-
panic!("Plugin does not exist: {}", std::any::type_name::<Target>())
41+
panic!(
42+
"Plugin does not exist: {}.",
43+
std::any::type_name::<Target>()
44+
)
4245
});
4346
self.order.insert(target_index, TypeId::of::<T>());
4447
self.plugins.insert(
@@ -59,7 +62,10 @@ impl PluginGroupBuilder {
5962
.find(|(_i, ty)| **ty == TypeId::of::<Target>())
6063
.map(|(i, _)| i)
6164
.unwrap_or_else(|| {
62-
panic!("Plugin does not exist: {}", std::any::type_name::<Target>())
65+
panic!(
66+
"Plugin does not exist: {}.",
67+
std::any::type_name::<Target>()
68+
)
6369
});
6470
self.order.insert(target_index + 1, TypeId::of::<T>());
6571
self.plugins.insert(
@@ -76,7 +82,7 @@ impl PluginGroupBuilder {
7682
let mut plugin_entry = self
7783
.plugins
7884
.get_mut(&TypeId::of::<T>())
79-
.expect("Cannot enable a plugin that does not exist");
85+
.expect("Cannot enable a plugin that does not exist.");
8086
plugin_entry.enabled = true;
8187
self
8288
}
@@ -85,7 +91,7 @@ impl PluginGroupBuilder {
8591
let mut plugin_entry = self
8692
.plugins
8793
.get_mut(&TypeId::of::<T>())
88-
.expect("Cannot disable a plugin that does not exist");
94+
.expect("Cannot disable a plugin that does not exist.");
8995
plugin_entry.enabled = false;
9096
self
9197
}

crates/bevy_app/src/schedule_runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl Plugin for ScheduleRunnerPlugin {
113113
f.as_ref().unchecked_ref(),
114114
dur.as_millis() as i32,
115115
)
116-
.expect("should register `setTimeout`");
116+
.expect("Should register `setTimeout`.");
117117
}
118118
let asap = Duration::from_millis(1);
119119

crates/bevy_asset/src/asset_server.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ use thiserror::Error;
1616
/// Errors that occur while loading assets with an AssetServer
1717
#[derive(Error, Debug)]
1818
pub enum AssetServerError {
19-
#[error("Asset folder path is not a directory.")]
19+
#[error("asset folder path is not a directory")]
2020
AssetFolderNotADirectory(String),
21-
#[error("No AssetLoader found for the given extension.")]
21+
#[error("no AssetLoader found for the given extension")]
2222
MissingAssetLoader(Option<String>),
23-
#[error("The given type does not match the type of the loaded asset.")]
23+
#[error("the given type does not match the type of the loaded asset")]
2424
IncorrectHandleType,
25-
#[error("Encountered an error while loading an asset.")]
25+
#[error("encountered an error while loading an asset")]
2626
AssetLoaderError(anyhow::Error),
27-
#[error("PathLoader encountered an error")]
27+
#[error("`PathLoader` encountered an error")]
2828
PathLoaderError(#[from] AssetIoError),
2929
}
3030

@@ -238,7 +238,7 @@ impl AssetServer {
238238
let mut asset_sources = self.server.asset_sources.write();
239239
let source_info = asset_sources
240240
.get_mut(&asset_path_id.source_path_id())
241-
.expect("AssetSource should exist at this point");
241+
.expect("`AssetSource` should exist at this point.");
242242
if version != source_info.version {
243243
return Ok(asset_path_id);
244244
}
@@ -317,7 +317,7 @@ impl AssetServer {
317317
continue;
318318
}
319319
let handle =
320-
self.load_untyped(child_path.to_str().expect("Path should be a valid string"));
320+
self.load_untyped(child_path.to_str().expect("Path should be a valid string."));
321321
handles.push(handle);
322322
}
323323
}
@@ -334,7 +334,7 @@ impl AssetServer {
334334
let ref_change = match receiver.try_recv() {
335335
Ok(ref_change) => ref_change,
336336
Err(TryRecvError::Empty) => break,
337-
Err(TryRecvError::Disconnected) => panic!("RefChange channel disconnected"),
337+
Err(TryRecvError::Disconnected) => panic!("RefChange channel disconnected."),
338338
};
339339
match ref_change {
340340
RefChange::Increment(handle_id) => *ref_counts.entry(handle_id).or_insert(0) += 1,
@@ -377,7 +377,7 @@ impl AssetServer {
377377
let asset_value = asset
378378
.value
379379
.take()
380-
.expect("Asset should exist at this point");
380+
.expect("Asset should exist at this point.");
381381
if let Some(asset_lifecycle) = asset_lifecycles.get(&asset_value.type_uuid()) {
382382
let asset_path =
383383
AssetPath::new_ref(&load_context.path, label.as_ref().map(|l| l.as_str()));
@@ -431,7 +431,7 @@ impl AssetServer {
431431
Err(TryRecvError::Empty) => {
432432
break;
433433
}
434-
Err(TryRecvError::Disconnected) => panic!("AssetChannel disconnected"),
434+
Err(TryRecvError::Disconnected) => panic!("AssetChannel disconnected."),
435435
}
436436
}
437437
}

crates/bevy_asset/src/filesystem_watcher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ impl Default for FilesystemWatcher {
1212
fn default() -> Self {
1313
let (sender, receiver) = crossbeam_channel::unbounded();
1414
let watcher: RecommendedWatcher = Watcher::new_immediate(move |res| {
15-
sender.send(res).expect("Watch event send failure");
15+
sender.send(res).expect("Watch event send failure.");
1616
})
17-
.expect("Failed to create filesystem watcher");
17+
.expect("Failed to create filesystem watcher.");
1818
FilesystemWatcher { watcher, receiver }
1919
}
2020
}

crates/bevy_asset/src/handle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl HandleUntyped {
274274
pub fn typed<T: Asset>(mut self) -> Handle<T> {
275275
if let HandleId::Id(type_uuid, _) = self.id {
276276
if T::TYPE_UUID != type_uuid {
277-
panic!("attempted to convert handle to invalid type");
277+
panic!("Attempted to convert handle to invalid type.");
278278
}
279279
}
280280
let handle_type = match &self.handle_type {

crates/bevy_asset/src/io/file_asset_io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub fn filesystem_watcher_system(asset_server: Res<AssetServer>) {
122122
let event = match watcher.receiver.try_recv() {
123123
Ok(result) => result.unwrap(),
124124
Err(TryRecvError::Empty) => break,
125-
Err(TryRecvError::Disconnected) => panic!("FilesystemWatcher disconnected"),
125+
Err(TryRecvError::Disconnected) => panic!("FilesystemWatcher disconnected."),
126126
};
127127
if let notify::event::Event {
128128
kind: notify::event::EventKind::Modify(_),

crates/bevy_asset/src/io/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ use thiserror::Error;
2424
/// Errors that occur while loading assets
2525
#[derive(Error, Debug)]
2626
pub enum AssetIoError {
27-
#[error("Path not found")]
27+
#[error("path not found")]
2828
NotFound(PathBuf),
29-
#[error("Encountered an io error while loading asset.")]
29+
#[error("encountered an io error while loading asset")]
3030
Io(#[from] io::Error),
31-
#[error("Failed to watch path")]
31+
#[error("failed to watch path")]
3232
PathWatchError(PathBuf),
3333
}
3434

crates/bevy_asset/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Plugin for AssetPlugin {
5555
let task_pool = app
5656
.resources()
5757
.get::<IoTaskPool>()
58-
.expect("IoTaskPool resource not found")
58+
.expect("`IoTaskPool` resource not found.")
5959
.0
6060
.clone();
6161

crates/bevy_asset/src/loader.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ impl<T: AssetDynamic> AssetLifecycle for AssetLifecycleChannel<T> {
152152
}))
153153
.unwrap()
154154
} else {
155-
panic!("failed to downcast asset to {}", std::any::type_name::<T>());
155+
panic!(
156+
"Failed to downcast asset to {}.",
157+
std::any::type_name::<T>()
158+
);
156159
}
157160
}
158161

crates/bevy_asset/src/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'a, 'b> From<&'a AssetPath<'b>> for AssetPathId {
143143
impl<'a> From<&'a str> for AssetPath<'a> {
144144
fn from(asset_path: &'a str) -> Self {
145145
let mut parts = asset_path.split('#');
146-
let path = Path::new(parts.next().expect("path must be set"));
146+
let path = Path::new(parts.next().expect("Path must be set."));
147147
let label = parts.next();
148148
AssetPath {
149149
path: Cow::Borrowed(path),

0 commit comments

Comments
 (0)