mirror of
https://github.com/aljazceru/goose.git
synced 2025-12-24 01:24:28 +01:00
Improve config file editing and recovery fallback mechanisms (#3082)
This commit is contained in:
@@ -28,7 +28,13 @@ import 'react-toastify/dist/ReactToastify.css';
|
||||
import { useConfig, MalformedConfigError } from './components/ConfigContext';
|
||||
import { ModelAndProviderProvider } from './components/ModelAndProviderContext';
|
||||
import { addExtensionFromDeepLink as addExtensionFromDeepLinkV2 } from './components/settings/extensions';
|
||||
import { backupConfig, initConfig, readAllConfig } from './api/sdk.gen';
|
||||
import {
|
||||
backupConfig,
|
||||
initConfig,
|
||||
readAllConfig,
|
||||
recoverConfig,
|
||||
validateConfig,
|
||||
} from './api/sdk.gen';
|
||||
import PermissionSettingsView from './components/settings/permission/PermissionSetting';
|
||||
|
||||
import { type SessionDetails } from './sessions';
|
||||
@@ -174,7 +180,39 @@ export default function App() {
|
||||
await backupConfig({ throwOnError: true });
|
||||
await initConfig();
|
||||
} else {
|
||||
throw new Error('Unable to read config file, it may be malformed');
|
||||
// Config appears corrupted, try recovery
|
||||
console.warn('Config file appears corrupted, attempting recovery...');
|
||||
try {
|
||||
// First try to validate the config
|
||||
try {
|
||||
await validateConfig({ throwOnError: true });
|
||||
// Config is valid but readAllConfig failed for another reason
|
||||
throw new Error('Unable to read config file, it may be malformed');
|
||||
} catch (validateError) {
|
||||
console.log('Config validation failed, attempting recovery...');
|
||||
|
||||
// Try to recover the config
|
||||
try {
|
||||
const recoveryResult = await recoverConfig({ throwOnError: true });
|
||||
console.log('Config recovery result:', recoveryResult);
|
||||
|
||||
// Try to read config again after recovery
|
||||
try {
|
||||
await readAllConfig({ throwOnError: true });
|
||||
console.log('Config successfully recovered and loaded');
|
||||
} catch (retryError) {
|
||||
console.warn('Config still corrupted after recovery, reinitializing...');
|
||||
await initConfig();
|
||||
}
|
||||
} catch (recoverError) {
|
||||
console.warn('Config recovery failed, reinitializing...');
|
||||
await initConfig();
|
||||
}
|
||||
}
|
||||
} catch (recoveryError) {
|
||||
console.error('Config recovery process failed:', recoveryError);
|
||||
throw new Error('Unable to read config file, it may be malformed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user