Don't silence migration errors + add backups Closes #2900

6cab3c7d20fd94e8865e2ffe3c94baf45bf605c8

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +6 -2Showing whitespace changes
src/users.js+6 -2
@@ -347,6 +347,8 @@ async function migrateSystemPrompts() {
347 if (fs.existsSync(migrateMarker)) {347 if (fs.existsSync(migrateMarker)) {
348 continue;348 continue;
349 }349 }
350 const backupsPath = path.join(directory.backups, '_sysprompt');
351 fs.mkdirSync(backupsPath, { recursive: true });
350 const defaultPrompts = await getDefaultSystemPrompts();352 const defaultPrompts = await getDefaultSystemPrompts();
351 const instucts = fs.readdirSync(directory.instruct);353 const instucts = fs.readdirSync(directory.instruct);
352 let migratedPrompts = [];354 let migratedPrompts = [];
@@ -356,6 +358,8 @@ async function migrateSystemPrompts() {
356 if (path.extname(instruct) === '.json' && !fs.existsSync(sysPromptPath)) {358 if (path.extname(instruct) === '.json' && !fs.existsSync(sysPromptPath)) {
357 const instructData = JSON.parse(fs.readFileSync(instructPath, 'utf8'));359 const instructData = JSON.parse(fs.readFileSync(instructPath, 'utf8'));
358 if ('system_prompt' in instructData && 'name' in instructData) {360 if ('system_prompt' in instructData && 'name' in instructData) {
361 const backupPath = path.join(backupsPath, `${instructData.name}.json`);
362 fs.cpSync(instructPath, backupPath, { force: true });
359 const syspromptData = { name: instructData.name, content: instructData.system_prompt };363 const syspromptData = { name: instructData.name, content: instructData.system_prompt };
360 migratedPrompts.push(syspromptData);364 migratedPrompts.push(syspromptData);
361 delete instructData.system_prompt;365 delete instructData.system_prompt;
@@ -374,8 +378,8 @@ async function migrateSystemPrompts() {
374 console.log(`Migrated system prompt ${sysPromptData.name} for ${directory.root.split(path.sep).pop()}`);378 console.log(`Migrated system prompt ${sysPromptData.name} for ${directory.root.split(path.sep).pop()}`);
375 }379 }
376 writeFileAtomicSync(migrateMarker, '');380 writeFileAtomicSync(migrateMarker, '');
377 } catch {381 } catch (error) {
378 // Ignore errors382 console.error('Error migrating system prompts:', error);
379 }383 }
380 }384 }
381}385}