Skip to content

Commit

Permalink
add position to scene errors (#8065)
Browse files Browse the repository at this point in the history
# Objective

- Fixes #6760
- adds line and position on line info to scene errors

```text
Before:
2023-03-12T22:38:59.103220Z  WARN bevy_asset::asset_server: encountered an error while loading an asset: Expected closing `)`
After:
2023-03-12T22:38:59.103220Z  WARN bevy_asset::asset_server: encountered an error while loading an asset: Expected closing `)` at scenes/test/scene.scn.ron:10:4
```

## Solution

- use span_error to get position info. This is what the ron crate does
internally to get the position info.
https://github.com/ron-rs/ron/blob/562963f88733cae0e3ca2a128b590817f0346343/src/options.rs#L158

## Changelog

- added line numbers to scene errors

---------

Co-authored-by: Paul Hansen <[email protected]>
  • Loading branch information
2 people authored and mockersf committed Mar 27, 2023
1 parent f61755a commit d6aba58
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions crates/bevy_scene/src/scene_loader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::serde::SceneDeserializer;
use anyhow::Result;
use anyhow::{anyhow, Result};
use bevy_app::AppTypeRegistry;
use bevy_asset::{AssetLoader, LoadContext, LoadedAsset};
use bevy_ecs::world::{FromWorld, World};
Expand Down Expand Up @@ -35,7 +35,17 @@ impl AssetLoader for SceneLoader {
let scene_deserializer = SceneDeserializer {
type_registry: &self.type_registry.read(),
};
let scene = scene_deserializer.deserialize(&mut deserializer)?;
let scene = scene_deserializer
.deserialize(&mut deserializer)
.map_err(|e| {
let span_error = deserializer.span_error(e);
anyhow!(
"{} at {}:{}",
span_error.code,
load_context.path().to_string_lossy(),
span_error.position,
)
})?;
load_context.set_default_asset(LoadedAsset::new(scene));
Ok(())
})
Expand Down

0 comments on commit d6aba58

Please sign in to comment.