Don't silence migration errors + add backups Closes #2900
| @@ -347,6 +347,8 @@ async function migrateSystemPrompts() { | ||
| 347 | 347 | if (fs.existsSync(migrateMarker)) { |
| 348 | 348 | continue; |
| 349 | 349 | } |
| 350 | + const backupsPath = path.join(directory.backups, '_sysprompt'); | |
| 351 | + fs.mkdirSync(backupsPath, { recursive: true }); | |
| 350 | 352 | const defaultPrompts = await getDefaultSystemPrompts(); |
| 351 | 353 | const instucts = fs.readdirSync(directory.instruct); |
| 352 | 354 | let migratedPrompts = []; |
| @@ -356,6 +358,8 @@ async function migrateSystemPrompts() { | ||
| 356 | 358 | if (path.extname(instruct) === '.json' && !fs.existsSync(sysPromptPath)) { |
| 357 | 359 | const instructData = JSON.parse(fs.readFileSync(instructPath, 'utf8')); |
| 358 | 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 | 363 | const syspromptData = { name: instructData.name, content: instructData.system_prompt }; |
| 360 | 364 | migratedPrompts.push(syspromptData); |
| 361 | 365 | delete instructData.system_prompt; |
| @@ -374,8 +378,8 @@ async function migrateSystemPrompts() { | ||
| 374 | 378 | console.log(`Migrated system prompt ${sysPromptData.name} for ${directory.root.split(path.sep).pop()}`); |
| 375 | 379 | } |
| 376 | 380 | writeFileAtomicSync(migrateMarker, ''); |
| 377 | 381 | } catch (error) { |
| 378 | - // Ignore errors | |
| 382 | + console.error('Error migrating system prompts:', error); | |
| 379 | 383 | } |
| 380 | 384 | } |
| 381 | 385 | } |