fix: resolve PR review findings for session storage error handling
- Move getSessionPath() inside try/catch in loadSessionById and deleteSession so validateSessionId exceptions are caught (FU2-001, FU2-004) - Add try/catch with logging to saveSession to prevent unhandled I/O throws (FU2-005) - Use session.updatedAt instead of new Date() in updateSessionModelConfig cache update to keep timestamps consistent (FU2-002) - Remove swallowing .catch() on archive/unarchive callbacks so errors propagate to parent handlers in Insights.tsx (FU2-006) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -219,7 +219,7 @@ export class SessionManager {
|
||||
for (const [projectId, cachedSession] of this.sessions) {
|
||||
if (cachedSession.id === sessionId) {
|
||||
cachedSession.modelConfig = modelConfig;
|
||||
cachedSession.updatedAt = new Date();
|
||||
cachedSession.updatedAt = session.updatedAt;
|
||||
this.sessions.set(projectId, cachedSession);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ export class SessionStorage {
|
||||
* Load a specific session from disk
|
||||
*/
|
||||
loadSessionById(projectPath: string, sessionId: string): InsightsSession | null {
|
||||
const sessionPath = this.paths.getSessionPath(projectPath, sessionId);
|
||||
if (!existsSync(sessionPath)) return null;
|
||||
|
||||
try {
|
||||
const sessionPath = this.paths.getSessionPath(projectPath, sessionId);
|
||||
if (!existsSync(sessionPath)) return null;
|
||||
|
||||
const content = readFileSync(sessionPath, 'utf-8');
|
||||
const session = JSON.parse(content) as InsightsSession;
|
||||
// Convert date strings back to Date objects
|
||||
@@ -58,13 +58,18 @@ export class SessionStorage {
|
||||
* Save session to disk
|
||||
*/
|
||||
saveSession(projectPath: string, session: InsightsSession): void {
|
||||
const sessionsDir = this.paths.getSessionsDir(projectPath);
|
||||
if (!existsSync(sessionsDir)) {
|
||||
mkdirSync(sessionsDir, { recursive: true });
|
||||
}
|
||||
try {
|
||||
const sessionsDir = this.paths.getSessionsDir(projectPath);
|
||||
if (!existsSync(sessionsDir)) {
|
||||
mkdirSync(sessionsDir, { recursive: true });
|
||||
}
|
||||
|
||||
const sessionPath = this.paths.getSessionPath(projectPath, session.id);
|
||||
writeFileSync(sessionPath, JSON.stringify(session, null, 2), 'utf-8');
|
||||
const sessionPath = this.paths.getSessionPath(projectPath, session.id);
|
||||
writeFileSync(sessionPath, JSON.stringify(session, null, 2), 'utf-8');
|
||||
} catch (error) {
|
||||
console.error(`[SessionStorage] Failed to save session ${session.id}:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,10 +146,10 @@ export class SessionStorage {
|
||||
* Delete a session from disk
|
||||
*/
|
||||
deleteSession(projectPath: string, sessionId: string): boolean {
|
||||
const sessionPath = this.paths.getSessionPath(projectPath, sessionId);
|
||||
if (!existsSync(sessionPath)) return false;
|
||||
|
||||
try {
|
||||
const sessionPath = this.paths.getSessionPath(projectPath, sessionId);
|
||||
if (!existsSync(sessionPath)) return false;
|
||||
|
||||
unlinkSync(sessionPath);
|
||||
return true;
|
||||
} catch {
|
||||
|
||||
@@ -307,8 +307,8 @@ export function ChatHistorySidebar({
|
||||
onCancelEdit={handleCancelEdit}
|
||||
onEditTitleChange={setEditTitle}
|
||||
onDelete={() => setDeleteSessionId(session.id)}
|
||||
onArchive={onArchiveSession ? () => onArchiveSession(session.id).catch((e) => console.error('Archive failed:', e)) : undefined}
|
||||
onUnarchive={onUnarchiveSession ? () => onUnarchiveSession(session.id).catch((e) => console.error('Unarchive failed:', e)) : undefined}
|
||||
onArchive={onArchiveSession ? () => onArchiveSession(session.id) : undefined}
|
||||
onUnarchive={onUnarchiveSession ? () => onUnarchiveSession(session.id) : undefined}
|
||||
isArchived={!!session.archivedAt}
|
||||
isSelectionMode={isSelectionMode}
|
||||
isSelected={selectedIds.has(session.id)}
|
||||
|
||||
Reference in New Issue
Block a user