`unwrap` considered harmful
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
Unwrap should generally be avoided. We already encourage contributors to avoid the use of `Option::unwrap`, yet crashes from panics are still one of the most common categories of issues we're seeing now.
## What solution would you like?
* Enable the clippy `unwrap_used` lint at a workspace level, and add `allow-unwrap-in-tests = true` to Clippy.toml.
* Replace actual expected crashes with `expect` or unwrap_or_else with a panic where possible, otherwise properly gracefully handle the error.
* Preferably avoid panicking in the renderer entirely, instead failing gracefully where possible by logging a warning and not rendering anything or using blatantly obvious errors (i.e. Valve's missing texture shader).
## What alternative(s) have you considered?
Leaving it as is. Keep crashing from unwraps.
## Status
- [ ] bevy_animation
- [ ] bevy_app
- [ ] bevy_asset
- [ ] bevy_core_pipeline
- [ ] bevy_core_widgets
- [ ] bevy_derive
- [ ] bevy_diagnostic
- [ ] bevy_ecs
- [ ] bevy_ecs_macros
- [ ] bevy_gilrs
- [ ] bevy_gltf
- [ ] bevy_gizmos
- [ ] bevy_image
- [ ] bevy_input_focus
- [ ] bevy_light
- [ ] bevy_log
- [ ] bevy_macro_utils
- [ ] bevy_math
- [ ] bevy_mesh
- [ ] bevy_pbr
- [ ] bevy_post_process
- [ ] bevy_reflect
- [ ] bevy_reflect_derive
- [ ] bevy_render_macros
- [ ] bevy_scene
- [ ] bevy_shader
- [ ] bevy_sprite_render
- [ ] bevy_text
- [ ] bevy_transform
- [ ] bevy_ui
- [ ] bevy_ui_render
- [ ] bevy_window
- [ ] bevy_winit
Contributor guide
Research direction
Start with the workspace Clippy configuration and Clippy.toml, then use the crate checklist in the issue to review each workspace member for unwrap usage. Confirm the lint allows unwraps in tests, replace or gracefully handle production cases as appropriate, and mark each crate complete once its checks pass without unintended panics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100