Commit c63c6c4
authored
🤖 Fix config array access compatibility issues (#274)
## Problem
After PR #273 merged, additional compatibility issues were discovered:
```
Cannot read properties of undefined (reading 'slice')
at App.tsx:374:29
```
This occurs when `projectConfig.workspaces` is undefined due to config
format differences between branches.
## Root Cause
The config loader uses type assertions without validation:
```typescript
const projectsMap = new Map<string, ProjectConfig>(
parsed.projects as Array<[string, ProjectConfig]>
);
```
If loaded config has `ProjectConfig` with missing `workspaces` field,
all array operations fail.
## Solution
Add `?? []` fallback to **all** array operations on
`projectConfig.workspaces`:
### Files Fixed
**App.tsx:**
- Line 242: `.find()` → `?? []).find()`
- Line 374: `.slice()` → `?? []).slice()`
**ProjectSidebar.tsx:**
- Line 823: `.map()` → `?? []).map()`
**ipcMain.ts:**
- Line 225: `.push()` → Initialize if undefined first
- Line 300: `.findIndex()` → `?? []).findIndex()`
- Line 367: Array assignment → Guard with existence check
- Line 808-810: `.length` and `.filter()` → `?? []).length` and `??
[]).filter()`
- Line 925-927: `.length` in error message → `?? []).length`
**config.ts:**
- Line 185: `for...of` loop → `?? [])`
## Testing
- ✅ `make typecheck` passes
- ✅ `make static-check` passes
- ✅ All array operations handle undefined gracefully
- ✅ Works with both old (no workspaces) and new (with workspaces)
configs
## Impact
Prevents all `.slice()`, `.map()`, `.filter()`, `.find()`, `.length`
crashes when switching between branches with different config formats.1 parent 93d2670 commit c63c6c4
File tree
6 files changed
+79
-81
lines changed- src
- components
- services
- tests/ipcMain
6 files changed
+79
-81
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
| 242 | + | |
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| |||
371 | 371 | | |
372 | 372 | | |
373 | 373 | | |
374 | | - | |
| 374 | + | |
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
820 | 820 | | |
821 | 821 | | |
822 | 822 | | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | | - | |
829 | | - | |
830 | | - | |
831 | | - | |
832 | | - | |
833 | | - | |
834 | | - | |
835 | | - | |
836 | | - | |
837 | | - | |
838 | | - | |
839 | | - | |
840 | | - | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
845 | | - | |
846 | | - | |
847 | | - | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
848 | 850 | | |
849 | 851 | | |
850 | 852 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| |||
136 | 139 | | |
137 | 140 | | |
138 | 141 | | |
139 | | - | |
140 | | - | |
141 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
142 | 149 | | |
143 | 150 | | |
144 | 151 | | |
| |||
182 | 189 | | |
183 | 190 | | |
184 | 191 | | |
185 | | - | |
186 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
187 | 195 | | |
188 | 196 | | |
189 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
182 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
183 | 193 | | |
184 | 194 | | |
185 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| 225 | + | |
225 | 226 | | |
226 | 227 | | |
227 | 228 | | |
| |||
297 | 298 | | |
298 | 299 | | |
299 | 300 | | |
300 | | - | |
301 | | - | |
302 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
303 | 307 | | |
304 | 308 | | |
305 | 309 | | |
| |||
363 | 367 | | |
364 | 368 | | |
365 | 369 | | |
366 | | - | |
| 370 | + | |
367 | 371 | | |
368 | 372 | | |
369 | 373 | | |
| |||
805 | 809 | | |
806 | 810 | | |
807 | 811 | | |
808 | | - | |
809 | | - | |
810 | | - | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
811 | 817 | | |
812 | 818 | | |
813 | 819 | | |
| |||
922 | 928 | | |
923 | 929 | | |
924 | 930 | | |
925 | | - | |
| 931 | + | |
926 | 932 | | |
927 | | - | |
| 933 | + | |
928 | 934 | | |
929 | 935 | | |
930 | 936 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 28 | + | |
| 29 | + | |
37 | 30 | | |
38 | 31 | | |
39 | 32 | | |
| |||
174 | 167 | | |
175 | 168 | | |
176 | 169 | | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
| 170 | + | |
| 171 | + | |
186 | 172 | | |
187 | 173 | | |
188 | 174 | | |
| |||
317 | 303 | | |
318 | 304 | | |
319 | 305 | | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
| 306 | + | |
| 307 | + | |
329 | 308 | | |
330 | 309 | | |
331 | 310 | | |
| |||
376 | 355 | | |
377 | 356 | | |
378 | 357 | | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
| 358 | + | |
| 359 | + | |
388 | 360 | | |
389 | 361 | | |
390 | 362 | | |
| |||
0 commit comments