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

d9a863810954097838d670b00b271007ce792cb8

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() {
347347 if (fs.existsSync(migrateMarker)) {
348348 continue;
349349 }
350+ const backupsPath = path.join(directory.backups, '_sysprompt');
351+ fs.mkdirSync(backupsPath, { recursive: true });
350352 const defaultPrompts = await getDefaultSystemPrompts();
351353 const instucts = fs.readdirSync(directory.instruct);
352354 let migratedPrompts = [];
@@ -356,6 +358,8 @@ async function migrateSystemPrompts() {
356358 if (path.extname(instruct) === '.json' && !fs.existsSync(sysPromptPath)) {
357359 const instructData = JSON.parse(fs.readFileSync(instructPath, 'utf8'));
358360 if ('system_prompt' in instructData && 'name' in instructData) {
361+ const backupPath = path.join(backupsPath, `${instructData.name}.json`);
362+ fs.cpSync(instructPath, backupPath, { force: true });
359363 const syspromptData = { name: instructData.name, content: instructData.system_prompt };
360364 migratedPrompts.push(syspromptData);
361365 delete instructData.system_prompt;
@@ -374,8 +378,8 @@ async function migrateSystemPrompts() {
374378 console.log(`Migrated system prompt ${sysPromptData.name} for ${directory.root.split(path.sep).pop()}`);
375379 }
376380 writeFileAtomicSync(migrateMarker, '');
377381 } catch (error) {
378- // Ignore errors
382+ console.error('Error migrating system prompts:', error);
379383 }
380384 }
381385}