mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-08 03:07:53 +00:00
Add proper error handling for API conversation history issues (#4312)
Co-authored-by: Eric Wheeler <roo-code@z.ewheeler.org>
This commit is contained in:
parent
38c7f360ac
commit
9b605c997c
1 changed files with 36 additions and 4 deletions
|
|
@ -21,17 +21,49 @@ export async function readApiMessages({
|
|||
const filePath = path.join(taskDir, GlobalFileNames.apiConversationHistory)
|
||||
|
||||
if (await fileExistsAtPath(filePath)) {
|
||||
return JSON.parse(await fs.readFile(filePath, "utf8"))
|
||||
const fileContent = await fs.readFile(filePath, "utf8")
|
||||
try {
|
||||
const parsedData = JSON.parse(fileContent)
|
||||
if (Array.isArray(parsedData) && parsedData.length === 0) {
|
||||
console.error(
|
||||
`[Roo-Debug] readApiMessages: Found API conversation history file, but it's empty (parsed as []). TaskId: ${taskId}, Path: ${filePath}`,
|
||||
)
|
||||
}
|
||||
return parsedData
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`[Roo-Debug] readApiMessages: Error parsing API conversation history file. TaskId: ${taskId}, Path: ${filePath}, Error: ${error}`,
|
||||
)
|
||||
throw error
|
||||
}
|
||||
} else {
|
||||
const oldPath = path.join(taskDir, "claude_messages.json")
|
||||
|
||||
if (await fileExistsAtPath(oldPath)) {
|
||||
const data = JSON.parse(await fs.readFile(oldPath, "utf8"))
|
||||
await fs.unlink(oldPath)
|
||||
return data
|
||||
const fileContent = await fs.readFile(oldPath, "utf8")
|
||||
try {
|
||||
const parsedData = JSON.parse(fileContent)
|
||||
if (Array.isArray(parsedData) && parsedData.length === 0) {
|
||||
console.error(
|
||||
`[Roo-Debug] readApiMessages: Found OLD API conversation history file (claude_messages.json), but it's empty (parsed as []). TaskId: ${taskId}, Path: ${oldPath}`,
|
||||
)
|
||||
}
|
||||
await fs.unlink(oldPath)
|
||||
return parsedData
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`[Roo-Debug] readApiMessages: Error parsing OLD API conversation history file (claude_messages.json). TaskId: ${taskId}, Path: ${oldPath}, Error: ${error}`,
|
||||
)
|
||||
// DO NOT unlink oldPath if parsing failed, throw error instead.
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we reach here, neither the new nor the old history file was found.
|
||||
console.error(
|
||||
`[Roo-Debug] readApiMessages: API conversation history file not found for taskId: ${taskId}. Expected at: ${filePath}`,
|
||||
)
|
||||
return []
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue