# Replace panicking unwraps in iterator and Option chains \(\#61277\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/4605a0f8dc09461747fee50b987da5e7dd1d76f5)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 4605a0f8dc09461747fee50b987da5e7dd1d76f5

Requested commit: 4605a0f8dc09461747fee50b987da5e7dd1d76f5

Commit: 4605a0f8dc09461747fee50b987da5e7dd1d76f5

Tree: 6b844b42d8cec0cd0aba77c12952f32afa3f8844

Author: Miguel Raz Guzmán Macedo

Committer: GitHub

## Message

```
Replace panicking unwraps in iterator and Option chains (#61277)

# Objective

Remove `.unwrap()` calls in iterator/`Option` chains that could panic at
runtime.

## Solution

Use `and_then`/`filter_map` with `.ok()` for fallible downcasts
(`entry_view_state.rs`) and keystroke parsing (`vim/command.rs`); use a
descriptive `expect` in `suggest_autoindents` where the invariant is
intentional (`buffer.rs`).

## Testing

- `cargo test -p language buffer` (69 passed)
- `cargo test -p vim command` (26 passed)
- `cargo test -p agent_ui entry_view` (3 passed)

## Self-Review Checklist:

- [x] I have reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [ ] The content adheres to Zed's UI standards
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- N/A
```

## Parents

- [d87dfaa4b33d5f686586fcb5dacdab3b30fef8f4](https://git.cafe/gitcafe/zed/commit/d87dfaa4b33d5f686586fcb5dacdab3b30fef8f4?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/4605a0f8dc09461747fee50b987da5e7dd1d76f5?format=markdown)
