mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-23 12:44:30 +00:00
fix(core): add exception handling to migrateFromFileStorage (#27229)
This commit is contained in:
@@ -180,14 +180,18 @@ describe('OAuthCredentialStorage', () => {
|
||||
expect(result).toEqual(mockCredentials);
|
||||
});
|
||||
|
||||
it('should throw an error if the migration file contains invalid JSON', async () => {
|
||||
it('should return null and log a warning if the migration file contains invalid JSON', async () => {
|
||||
vi.spyOn(mockHybridTokenStorage, 'getCredentials').mockResolvedValue(
|
||||
null,
|
||||
);
|
||||
vi.spyOn(fs, 'readFile').mockResolvedValue('invalid json');
|
||||
|
||||
await expect(OAuthCredentialStorage.loadCredentials()).rejects.toThrow(
|
||||
'Failed to load OAuth credentials',
|
||||
const result = await OAuthCredentialStorage.loadCredentials();
|
||||
|
||||
expect(result).toBeNull();
|
||||
expect(coreEvents.emitFeedback).toHaveBeenCalledWith(
|
||||
'warning',
|
||||
expect.stringContaining('Corrupted OAuth credential file'),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -129,8 +129,17 @@ export class OAuthCredentialStorage {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const credentials: Credentials = JSON.parse(credsJson);
|
||||
let credentials: Credentials;
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
credentials = JSON.parse(credsJson);
|
||||
} catch {
|
||||
coreEvents.emitFeedback(
|
||||
'warning',
|
||||
`Corrupted OAuth credential file at ${oldFilePath}, skipping migration`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Save to new storage
|
||||
await this.saveCredentials(credentials);
|
||||
|
||||
Reference in New Issue
Block a user