Skip to content

Commit

Permalink
Prefer Display over Debug (#16112)
Browse files Browse the repository at this point in the history
# Objective

Fixes #16104

## Solution

I removed all instances of `:?` and put them back one by one where it
caused an error.

I removed some bevy_utils helper functions that were only used in 2
places and don't add value. See: #11478

## Testing

CI should catch the mistakes

## Migration Guide

`bevy::utils::{dbg,info,warn,error}` were removed. Use
`bevy::utils::tracing::{debug,info,warn,error}` instead.

---------

Co-authored-by: SpecificProtagonist <vincentjunge@posteo.net>
  • Loading branch information
BenjaminBrienen and SpecificProtagonist authored Dec 27, 2024
1 parent 80094c6 commit 64efd08
Show file tree
Hide file tree
Showing 59 changed files with 155 additions and 170 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,8 +1057,8 @@ pub fn animate_targets(
(player, graph_handle.id())
} else {
trace!(
"Either an animation player {:?} or a graph was missing for the target \
entity {:?} ({:?}); no animations will play this frame",
"Either an animation player {} or a graph was missing for the target \
entity {} ({:?}); no animations will play this frame",
player_id,
entity_mut.id(),
entity_mut.get::<Name>(),
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_asset/src/io/file/file_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ impl AssetWatcher for FileWatcher {}
pub(crate) fn get_asset_path(root: &Path, absolute_path: &Path) -> (PathBuf, bool) {
let relative_path = absolute_path.strip_prefix(root).unwrap_or_else(|_| {
panic!(
"FileWatcher::get_asset_path() failed to strip prefix from absolute path: absolute_path={:?}, root={:?}",
absolute_path,
root
"FileWatcher::get_asset_path() failed to strip prefix from absolute path: absolute_path={}, root={}",
absolute_path.display(),
root.display()
)
});
let is_meta = relative_path
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_asset/src/io/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ impl FileAssetWriter {
if create_root {
if let Err(e) = std::fs::create_dir_all(&root_path) {
error!(
"Failed to create root directory {:?} for file asset writer: {:?}",
root_path, e
"Failed to create root directory {} for file asset writer: {}",
root_path.display(),
e
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1684,9 +1684,9 @@ mod tests {
);
}
}
_ => panic!("Unexpected error type {:?}", read_error),
_ => panic!("Unexpected error type {}", read_error),
},
_ => panic!("Unexpected error type {:?}", error.error),
_ => panic!("Unexpected error type {}", error.error),
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions crates/bevy_asset/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,18 @@ impl AssetProcessor {
// Therefore, we shouldn't automatically delete the asset ... that is a
// user-initiated action.
debug!(
"Meta for asset {:?} was removed. Attempting to re-process",
"Meta for asset {} was removed. Attempting to re-process",
AssetPath::from_path(&path).with_source(source.id())
);
self.process_asset(source, path).await;
}

/// Removes all processed assets stored at the given path (respecting transactionality), then removes the folder itself.
async fn handle_removed_folder(&self, source: &AssetSource, path: &Path) {
debug!("Removing folder {:?} because source was removed", path);
debug!(
"Removing folder {} because source was removed",
path.display()
);
let processed_reader = source.processed_reader().unwrap();
match processed_reader.read_directory(path).await {
Ok(mut path_stream) => {
Expand Down Expand Up @@ -739,7 +742,7 @@ impl AssetProcessor {
) -> Result<ProcessResult, ProcessError> {
// TODO: The extension check was removed now that AssetPath is the input. is that ok?
// TODO: check if already processing to protect against duplicate hot-reload events
debug!("Processing {:?}", asset_path);
debug!("Processing {}", asset_path);
let server = &self.server;
let path = asset_path.path();
let reader = source.reader();
Expand Down Expand Up @@ -1237,7 +1240,7 @@ impl ProcessorAssetInfos {
) {
match result {
Ok(ProcessResult::Processed(processed_info)) => {
debug!("Finished processing \"{:?}\"", asset_path);
debug!("Finished processing \"{}\"", asset_path);
// clean up old dependents
let old_processed_info = self
.infos
Expand All @@ -1260,7 +1263,7 @@ impl ProcessorAssetInfos {
}
}
Ok(ProcessResult::SkippedNotChanged) => {
debug!("Skipping processing (unchanged) \"{:?}\"", asset_path);
debug!("Skipping processing (unchanged) \"{}\"", asset_path);
let info = self.get_mut(&asset_path).expect("info should exist");
// NOTE: skipping an asset on a given pass doesn't mean it won't change in the future as a result
// of a dependency being re-processed. This means apps might receive an "old" (but valid) asset first.
Expand All @@ -1271,7 +1274,7 @@ impl ProcessorAssetInfos {
info.update_status(ProcessStatus::Processed).await;
}
Ok(ProcessResult::Ignored) => {
debug!("Skipping processing (ignored) \"{:?}\"", asset_path);
debug!("Skipping processing (ignored) \"{}\"", asset_path);
}
Err(ProcessError::ExtensionRequired) => {
// Skip assets without extensions
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/server/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl AssetInfos {
} else {
// the dependency id does not exist, which implies it was manually removed or never existed in the first place
warn!(
"Dependency {:?} from asset {:?} is unknown. This asset's dependency load status will not switch to 'Loaded' until the unknown dependency is loaded.",
"Dependency {} from asset {} is unknown. This asset's dependency load status will not switch to 'Loaded' until the unknown dependency is loaded.",
dep_id, loaded_asset_id
);
true
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ impl AssetServer {
.spawn(async move {
let Ok(source) = server.get_source(path.source()) else {
error!(
"Failed to load {path}. AssetSource {:?} does not exist",
"Failed to load {path}. AssetSource {} does not exist",
path.source()
);
return;
Expand All @@ -918,7 +918,7 @@ impl AssetServer {
Ok(reader) => reader,
Err(_) => {
error!(
"Failed to load {path}. AssetSource {:?} does not have a processed AssetReader",
"Failed to load {path}. AssetSource {} does not have a processed AssetReader",
path.source()
);
return;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_audio/src/audio_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub(crate) fn play_queued_audio_system<Source: Asset + Decodable>(
// the user may have made a mistake.
if ear_positions.multiple_listeners() {
warn!(
"Multiple SpatialListeners found. Using {:?}.",
"Multiple SpatialListeners found. Using {}.",
ear_positions.query.iter().next().unwrap().0
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_color/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ macro_rules! assert_approx_eq {
if ($x - $y).abs() >= $d {
panic!(
"assertion failed: `(left !== right)` \
(left: `{:?}`, right: `{:?}`, tolerance: `{:?}`)",
(left: `{}`, right: `{}`, tolerance: `{}`)",
$x, $y, $d
);
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct Position { x: f32, y: f32 }

fn print_position(query: Query<(Entity, &Position)>) {
for (entity, position) in &query {
println!("Entity {:?} is at position: x {}, y {}", entity, position.x, position.y);
println!("Entity {} is at position: x {}, y {}", entity, position.x, position.y);
}
}
```
Expand Down Expand Up @@ -172,7 +172,7 @@ struct Player;
struct Alive;

// Gets the Position component of all Entities with Player component and without the Alive
// component.
// component.
fn system(query: Query<&Position, (With<Player>, Without<Alive>)>) {
for position in &query {
}
Expand Down Expand Up @@ -340,7 +340,7 @@ let mut world = World::new();
let entity = world.spawn_empty().id();

world.add_observer(|trigger: Trigger<Explode>, mut commands: Commands| {
println!("Entity {:?} goes BOOM!", trigger.target());
println!("Entity {} goes BOOM!", trigger.target());
commands.entity(trigger.target()).despawn();
});

Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/examples/change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ fn print_changed_entities(
entity_with_mutated_component: Query<(Entity, &Age), Changed<Age>>,
) {
for entity in &entity_with_added_component {
println!(" {entity:?} has it's first birthday!");
println!(" {entity} has it's first birthday!");
}
for (entity, value) in &entity_with_mutated_component {
println!(" {entity:?} is now {value:?} frames old");
println!(" {entity} is now {value:?} frames old");
}
}

Expand All @@ -98,7 +98,7 @@ fn age_all_entities(mut entities: Query<&mut Age>) {
fn remove_old_entities(mut commands: Commands, entities: Query<(Entity, &Age)>) {
for (entity, age) in &entities {
if age.frames > 2 {
println!(" despawning {entity:?} due to age > 2");
println!(" despawning {entity} due to age > 2");
commands.entity(entity).despawn();
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/examples/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn sending_system(mut event_writer: EventWriter<MyEvent>) {
fn receiving_system(mut event_reader: EventReader<MyEvent>) {
for my_event in event_reader.read() {
println!(
" Received message {:?}, with random value of {}",
" Received message {}, with random value of {}",
my_event.message, my_event.random_value
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/observer/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub type ObserverRunner = fn(DeferredWorld, ObserverTrigger, PtrMut, propagate:
/// struct Explode;
///
/// world.add_observer(|trigger: Trigger<Explode>, mut commands: Commands| {
/// println!("Entity {:?} goes BOOM!", trigger.target());
/// println!("Entity {} goes BOOM!", trigger.target());
/// commands.entity(trigger.target()).despawn();
/// });
///
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/query/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ unsafe impl<T: Component> QueryFilter for Without<T> {
/// #
/// fn print_cool_entity_system(query: Query<Entity, Or<(Changed<Color>, Changed<Node>)>>) {
/// for entity in &query {
/// println!("Entity {:?} got a new style or color", entity);
/// println!("Entity {} got a new style or color", entity);
/// }
/// }
/// # bevy_ecs::system::assert_is_system(print_cool_entity_system);
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/removal_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl RemovedComponentEvents {
/// # #[derive(Component)]
/// # struct MyComponent;
/// fn react_on_removal(mut removed: RemovedComponents<MyComponent>) {
/// removed.read().for_each(|removed_entity| println!("{:?}", removed_entity));
/// removed.read().for_each(|removed_entity| println!("{}", removed_entity));
/// }
/// # bevy_ecs::system::assert_is_system(react_on_removal);
/// ```
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_ecs/src/system/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl<'w, 's> Commands<'w, 's> {
#[track_caller]
fn panic_no_entity(entities: &Entities, entity: Entity) -> ! {
panic!(
"Attempting to create an EntityCommands for entity {entity:?}, which {}",
"Attempting to create an EntityCommands for entity {entity}, which {}",
entities.entity_does_not_exist_error_details_message(entity)
);
}
Expand Down Expand Up @@ -1405,7 +1405,7 @@ impl<'a> EntityCommands<'a> {
entity.insert_by_id(component_id, ptr);
});
} else {
panic!("error[B0003]: {caller}: Could not insert a component {component_id:?} (with type {}) for entity {entity:?}, which {}. See: https://bevyengine.org/learn/errors/b0003", core::any::type_name::<T>(), world.entities().entity_does_not_exist_error_details_message(entity));
panic!("error[B0003]: {caller}: Could not insert a component {component_id:?} (with type {}) for entity {entity}, which {}. See: https://bevyengine.org/learn/errors/b0003", core::any::type_name::<T>(), world.entities().entity_does_not_exist_error_details_message(entity));
}
})
}
Expand Down Expand Up @@ -1739,7 +1739,7 @@ impl<'a> EntityCommands<'a> {
/// .spawn_empty()
/// // Closures with this signature implement `EntityCommand`.
/// .queue(|entity: EntityWorldMut| {
/// println!("Executed an EntityCommand for {:?}", entity.id());
/// println!("Executed an EntityCommand for {}", entity.id());
/// });
/// # }
/// # bevy_ecs::system::assert_is_system(my_system);
Expand Down Expand Up @@ -2119,7 +2119,7 @@ impl<'a, T: Component> EntityEntryCommands<'a, T> {
caller,
);
} else {
panic!("error[B0003]: {caller}: Could not insert a bundle (of type `{}`) for {entity:?}, which {}. See: https://bevyengine.org/learn/errors/b0003", core::any::type_name::<T>(), world.entities().entity_does_not_exist_error_details_message(entity) );
panic!("error[B0003]: {caller}: Could not insert a bundle (of type `{}`) for {entity}, which {}. See: https://bevyengine.org/learn/errors/b0003", core::any::type_name::<T>(), world.entities().entity_does_not_exist_error_details_message(entity) );
}
});
self
Expand Down Expand Up @@ -2225,7 +2225,7 @@ fn insert<T: Bundle>(bundle: T, mode: InsertMode) -> impl EntityCommand {
caller,
);
} else {
panic!("error[B0003]: {caller}: Could not insert a bundle (of type `{}`) for entity {entity:?}, which {}. See: https://bevyengine.org/learn/errors/b0003", core::any::type_name::<T>(), world.entities().entity_does_not_exist_error_details_message(entity));
panic!("error[B0003]: {caller}: Could not insert a bundle (of type `{}`) for entity {entity}, which {}. See: https://bevyengine.org/learn/errors/b0003", core::any::type_name::<T>(), world.entities().entity_does_not_exist_error_details_message(entity));
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions crates/bevy_ecs/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1652,9 +1652,10 @@ mod tests {
assert_is_system(returning::<&str>.map(u64::from_str).map(Result::unwrap));
assert_is_system(static_system_param);
assert_is_system(
exclusive_in_out::<(), Result<(), std::io::Error>>.map(|result| {
if let Err(error) = result {
log::error!("{:?}", error);
exclusive_in_out::<(), Result<(), std::io::Error>>.map(|_out| {
#[cfg(feature = "trace")]
if let Err(error) = _out {
tracing::error!("{}", error);
}
}),
);
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/system/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
/// ) {
/// for friends in &friends_query {
/// for counter in counter_query.iter_many(&friends.list) {
/// println!("Friend's counter: {:?}", counter.value);
/// println!("Friend's counter: {}", counter.value);
/// }
/// }
/// }
Expand Down Expand Up @@ -674,7 +674,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
/// for friends in &friends_query {
/// let mut iter = counter_query.iter_many_mut(&friends.list);
/// while let Some(mut counter) = iter.fetch_next() {
/// println!("Friend's counter: {:?}", counter.value);
/// println!("Friend's counter: {}", counter.value);
/// counter.value += 1;
/// }
/// }
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ impl World {
#[track_caller]
fn panic_no_entity(world: &World, entity: Entity) -> ! {
panic!(
"Entity {entity:?} {}",
"Entity {entity} {}",
world
.entities
.entity_does_not_exist_error_details_message(entity)
Expand Down Expand Up @@ -862,7 +862,7 @@ impl World {
let entity_location = self
.entities()
.get(entity)
.unwrap_or_else(|| panic!("Entity {entity:?} does not exist"));
.unwrap_or_else(|| panic!("Entity {entity} does not exist"));

let archetype = self
.archetypes()
Expand Down Expand Up @@ -1336,7 +1336,7 @@ impl World {
true
} else {
if log_warning {
warn!("error[B0003]: {caller}: Could not despawn entity {entity:?}, which {}. See: https://bevyengine.org/learn/errors/b0003", self.entities.entity_does_not_exist_error_details_message(entity));
warn!("error[B0003]: {caller}: Could not despawn entity {entity}, which {}. See: https://bevyengine.org/learn/errors/b0003", self.entities.entity_does_not_exist_error_details_message(entity));
}
false
}
Expand Down Expand Up @@ -2498,11 +2498,11 @@ impl World {
)
};
} else {
panic!("error[B0003]: Could not insert a bundle (of type `{}`) for entity {entity:?}, which {}. See: https://bevyengine.org/learn/errors/b0003", core::any::type_name::<B>(), self.entities.entity_does_not_exist_error_details_message(entity));
panic!("error[B0003]: Could not insert a bundle (of type `{}`) for entity {entity}, which {}. See: https://bevyengine.org/learn/errors/b0003", core::any::type_name::<B>(), self.entities.entity_does_not_exist_error_details_message(entity));
}
}
} else {
panic!("error[B0003]: Could not insert a bundle (of type `{}`) for entity {first_entity:?}, which {}. See: https://bevyengine.org/learn/errors/b0003", core::any::type_name::<B>(), self.entities.entity_does_not_exist_error_details_message(first_entity));
panic!("error[B0003]: Could not insert a bundle (of type `{}`) for entity {first_entity}, which {}. See: https://bevyengine.org/learn/errors/b0003", core::any::type_name::<B>(), self.entities.entity_does_not_exist_error_details_message(first_entity));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/world/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pub enum GetComponentReflectError {
NoCorrespondingComponentId(TypeId),

/// The given [`Entity`] does not have a [`Component`] corresponding to the given [`TypeId`].
#[error("The given `Entity` {entity:?} does not have a `{component_name:?}` component ({component_id:?}, which corresponds to {type_id:?})")]
#[error("The given `Entity` {entity} does not have a `{component_name:?}` component ({component_id:?}, which corresponds to {type_id:?})")]
EntityDoesNotHaveComponent {
/// The given [`Entity`].
entity: Entity,
Expand Down
Loading

0 comments on commit 64efd08

Please sign in to comment.