Commit cb428a2
committed
feat(parse_size): Add comprehensive builder validation to prevent fragile configurations
Addresses PR uutils#9653 review feedback about 'fragile commands' by implementing
fail-fast validation in Parser builder pattern.
Changes:
- Add ParserBuilderError enum with 8 validation error variants
- Refactor builder methods to return Result<&mut Self, ParserBuilderError>
- Implement comprehensive unit validation (57 valid units including k/m/g/t)
- Add cross-validation between builder settings (default_unit vs allow_list)
- Detect conflicts (b_byte_count with 'b' unit, '%' with size units)
- Update all call sites (sort, du, df, od) to handle new error types
- Fix invalid '%' unit in sort's parse_byte_count allow_list
Benefits:
- Configuration errors detected immediately (not during parsing)
- Clear error messages listing invalid/conflicting settings
- Maintains backward compatibility through explicit error reporting
Files modified:
- src/uucore/src/lib/features/parser/parse_size.rs (core implementation)
- src/uu/sort/src/sort.rs (error handling + fix invalid '%')
- src/uu/du/src/du.rs (error handling)
- src/uu/df/src/df.rs (error handling)
- src/uu/od/src/od.rs (error handling)1 parent 9ffe95e commit cb428a2
File tree
8 files changed
+447
-51
lines changed- .vscode/cspell.dictionaries
- src
- uucore
- src/lib/features/parser
- uu
- df/src
- du/src
- od/src
- sort/src
- tests/by-util
8 files changed
+447
-51
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
155 | 157 | | |
156 | 158 | | |
157 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1502 | 1502 | | |
1503 | 1503 | | |
1504 | 1504 | | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
1505 | 1508 | | |
1506 | 1509 | | |
1507 | 1510 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
804 | 804 | | |
805 | 805 | | |
806 | 806 | | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
807 | 810 | | |
808 | 811 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
313 | | - | |
314 | | - | |
315 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
| |||
2955 | 2955 | | |
2956 | 2956 | | |
2957 | 2957 | | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
2958 | 2961 | | |
2959 | 2962 | | |
2960 | 2963 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| |||
0 commit comments