Skip to content

Return/log an error when attempting to load an empty asset path.#23654

Open
andriyDev wants to merge 4 commits intobevyengine:mainfrom
andriyDev:reject-empty-path
Open

Return/log an error when attempting to load an empty asset path.#23654
andriyDev wants to merge 4 commits intobevyengine:mainfrom
andriyDev:reject-empty-path

Conversation

@andriyDev
Copy link
Copy Markdown
Contributor

Objective

  • Partially addresses https://discord.com/channels/691052431525675048/749332104487108618/1489425547598762095
    • Currently BSN will attempt to load a string whenever a handle is seen. Unfortunately, BSN treats nothing to mean the empty string. The asset system then tries to load the empty string and returns various unhelpful error messages depending on your OS.
    • This doesn't totally fix the issue - BSN should probably not be loading these paths at all. But more generally the asset system should just ignore empty paths entirely since it should never load a meaningful path.

Solution

  • In every load variant, add a check for the empty path and log an error or return an error in that case. We also return a default handle in that case (where necessary).
  • Intentionally don't handle load_folder. You could theoretically want to load the root folder!

To address some alternative implementations:

  • There isn't a common loading API that all roads lead to! Each one is a little different, so we need to handle them in each case. We should investigate collapsing some of these though.
  • AssetPath still needs to be allowed to parse an empty path, since for stuff like joining asset paths, that needs to support cases like "only a subasset label", or "joining the empty path with some subdir path".

Testing

  • Added a test to test all the load variants on AssetServer.

@andriyDev andriyDev added C-Bug An unexpected or incorrect behavior A-Assets Load files from disk to use for things like images, models, and sounds D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 4, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Assets Apr 4, 2026
@andriyDev andriyDev added this to the 0.19 milestone Apr 4, 2026
@alice-i-cecile alice-i-cecile added the C-Usability A targeted quality-of-life change that makes Bevy easier to use label Apr 4, 2026
Copy link
Copy Markdown
Contributor

@greeble-dev greeble-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I would tweak the message slightly - "Attempting to load an asset with an empty path" seems just a bit clearer - but it's not a big deal.

There's a few places that might be missing checks?

  • AssetServer::reload/reload_internal.
  • LoadContext::read_asset_bytes.
  • Maybe ProcessContext::load_source_asset - not sure about that case.

@andriyDev
Copy link
Copy Markdown
Contributor Author

@greeble-dev

  • AssetServer::reload/reload_internal should be ok since it should just find no handles to reload and no dependencies on that path (since a dependency also requires a valid load), so it should do nothing. We could do it as a fast check for optimization? I don't care about this though - I'd rather it just be handled by the existing code.
  • ProcessContext::load_source_asset doesn't need it since we don't give it a path at all. The path is deduced based on which asset in your source assets is being processed. So this will always load a good path. Though, we should really allow ProcessContext to read any unprocessed asset - then we would want to add this check!

@andriyDev andriyDev added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 4, 2026
github-merge-queue bot pushed a commit that referenced this pull request Apr 4, 2026
…3656)

# Objective

- Not setting any value to a handle in BSN results in BSN attempting to
load an empty path! This is not handled well (see #23654 for some fixes
there).
- Even with #23654, we would still get errors in the logs which is not
ideal.

## Solution

- Use the Handle variant for the template!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

4 participants