Skip to content

Make get_mapped_range return a Result rather than panicking#9281

Open
atlv24 wants to merge 1 commit intogfx-rs:trunkfrom
atlv24:ad/dont-panic
Open

Make get_mapped_range return a Result rather than panicking#9281
atlv24 wants to merge 1 commit intogfx-rs:trunkfrom
atlv24:ad/dont-panic

Conversation

@atlv24
Copy link
Copy Markdown
Collaborator

@atlv24 atlv24 commented Mar 22, 2026

Connections

Description
We shouldn't be panicking in get_mapped_range. Let's return a result.

Testing
Existing panic tests now check for Err instead.

Squash or Rebase?

Whatever your heart desires

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@ByteNybbler
Copy link
Copy Markdown

LGTM

github-merge-queue bot pushed a commit to bevyengine/bevy that referenced this pull request Mar 23, 2026
# Objective

- Completes goal and closes #23029
- Culmination of #22761, #23350, #23349, #23433, #23458, #23444, #23459,
#23461, #23463, #22714, #22759, #16481

## Solution

- Add a release note.
- Re-export a wgpu type that you need to match on to handle errors.

## Testing

- cargo run --example render_recovery with all the other PRs merged in.
Press 5 and then V, the app will not crash. Note that D for "destroy
device" will still crash: this is a WGPU problem resolved by
gfx-rs/wgpu#9281.

# Note

I opted not to change the default recovery behavior yet. I believe we
need testing in user projects and just general trodding of this code
path before committing to a new default. It works in a simple example,
it might not work in a complex project. We need to field test this and
likely iterate to really call this ready IMO.
@cwfitzgerald cwfitzgerald self-assigned this Mar 25, 2026
Copy link
Copy Markdown
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Some note, looks broadly good

Comment on lines +779 to +781
return Err(MapRangeError(
"tried to call get_mapped_range(_mut) on an unmapped buffer".into(),
));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of using stringy errors, we should use proper thiserror errors. Right now in the docs we have lost information about what errors are possible as we no longer spell out the exact logic.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah yes because webgpu. Stringy errors are fine, but lets keep the explanation about what exact error cases you will hit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants