1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
- ---
1. 2.
**Total: 16 critical unwraps eliminated** ✅
**Issue:** `.and_hms_opt()` can return `None`, causing panic on invalid times
**Fix:** Proper error propagation with descriptive message
```rust
// Before
naive_date.and_hms_opt(0, 0, 0).unwrap()
// After
naive_date.and_hms_opt(0, 0, 0).ok_or_else(||
)?
```
**Issue:** `contains() + find().unwrap()` anti-pattern
**Fix:** Replace with `if let Some()`
```rust
// Before
if clause.contains(" count ") {
// After
if let Some(pos) = clause.find(" count ") {
```
**Files affected:**
- --
**Issue:** `.unwrap()` on iterator after empty check - technically safe but unclear
**Fix:** Use `.expect()` with invariant documentation
```rust
// Before
if conditions.is_empty() { return Err(...); }
let mut result = iter.next().unwrap();
// After
let mut result = iter.next()
```
**Lines:** 817, 839 in grl_no_regex.rs; 763, 785, 1251 in grl.rs
**Issue:** `.chars().next().unwrap()` without null check
**Fix:** Use `.expect()` or `if let`
```rust
// Before
let first = s.chars().next().unwrap();
// After (option 1)
let first = s.chars().next()
// After (option 2)
if let Some(first_char) = op.chars().next() {
```
**Lines:** 1368, 1085 in grl_no_regex.rs; 1350 in grl.rs
**Issue:** `.strip_prefix("!").unwrap()` assumes prefix exists
**Fix:** Proper error handling
```rust
// Before
let inner = clause.strip_prefix("!").unwrap();
// After
let inner = clause.strip_prefix('!').ok_or_else(|| {
})?;
```
**Line:** 804 in grl.rs
```bash
cargo test --all-features
cargo clippy --all-targets --all-features -- -D warnings
git diff src/parser/grl.rs src/parser/grl_no_regex.rs
```
This fixes **HIGH PRIORITY Issue #9: "Excessive unwrap/expect in Parser"** from the technical review:
- ---
**Status: READY TO MERGE** ✅
All critical parser unwraps have been systematically eliminated while:
- ----
**Recommendation:** Merge to main and include in next release (v1.19.3)