-
Notifications
You must be signed in to change notification settings - Fork 22
🤖 Add forward compatibility for workspace path access #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Make workspace path access defensive with optional chaining to prevent crashes when switching between branches with different config formats. Changes: - Add optional chaining (?.) to all workspacePath.split() calls - Provide fallbacks using workspaceId when path is undefined - Affects App.tsx and utils/commands/sources.ts This allows the app to work with both: - Old config format (only 'path' field) - New config format (with 'id', 'name', and 'path' fields) Prevents 'Cannot read properties of undefined' errors when config has fields that the current code version doesn't expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR.
Don't render AIView if workspacePath is undefined to prevent crashes in features that depend on a valid path (like terminal operations). This ensures we show the welcome screen instead of attempting to render a workspace view with invalid/missing data.
## 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.
Problem
When switching between branches with different config formats, the app crashes with:
This occurs because newer branches may add fields to the workspace config that older code doesn't expect (e.g.,
namedWorkspacePath,id,name).Solution
Add optional chaining (
?.) to allworkspacePath.split()calls and provide sensible fallbacks:Changes
workspacePathaccess defensive in ErrorBoundary and AIViewworkspacePathaccess defensive in all command sourcesTesting
make typecheckpasses ✅path) and new format (id,name,path)Impact
This is a defensive improvement that makes the app more robust. No behavior changes for normal operation - only prevents crashes when config format mismatches occur.