Improve config file editing and recovery fallback mechanisms (#3082)

This commit is contained in:
Zane
2025-06-26 11:08:57 -07:00
committed by GitHub
parent 39b943ee85
commit 79553e0b8b
8 changed files with 722 additions and 187 deletions

View File

@@ -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');
}
}
}