google-gemini / google-gemini/gemini-cli
bug: Gracefully handle failed extension updates in extension-manager.ts
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
### What happened?
In `packages/cli/src/config/extension-manager.ts`, when upgrading/updating an extension, the files are copied directly to the `destinationPath` (overwriting the existing extension files). Right after copying, the manager attempts to load the new extension:
```typescript
// TODO: Gracefully handle this call failing, we should back up the old
// extension prior to overwriting it and then restore and restart it.
extension = await this.loadExtension(destinationPath);
```
If `loadExtension` throws an error (e.g. because of a syntax error in the updated JavaScript/TypeScript files, a malformed config, or missing files), the update process fails, but the old working version of the extension has already been deleted and overwritten. The user is left with a broken/unusable extension.
### What did you expect to happen?
Before copying the update over an existing extension, the extension manager should create a backup of the old extension directory. If `loadExtension` fails to load the update, the manager should catch the error, restore the backup, and reload the previous working version while logging/displaying a graceful error message to the user.
### Client information
Platform: All
Core version: 0.51.0
### Anything else we need to know?
Relevant code segment:
https://github.com/google-gemini/gemini-cli/blob/main/packages/cli/src/config/extension-manager.ts#L450
Contributor guide
Research direction
Start in packages/cli/src/config/extension-manager.ts around the update flow and the loadExtension(destinationPath) call. Trace how the existing extension is overwritten and how loading failures are reported. Done means a failed update preserves and reloads the previous working extension while providing a graceful error to the user.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100