Fix issue where for some users fs readfile was returning undefined instead of failing

This commit is contained in:
Saoud Rizwan
2024-08-08 02:56:06 -04:00
parent 911dd159cd
commit d44cc99ce1

View File

@@ -419,8 +419,14 @@ export class ClaudeDev {
.access(absolutePath) .access(absolutePath)
.then(() => true) .then(() => true)
.catch(() => false) .catch(() => false)
// Some users reported that fs readfile would return undefined instead of failing
let originalContent: string | undefined
if (fileExists) { if (fileExists) {
const originalContent = await fs.readFile(absolutePath, "utf-8") originalContent = await fs.readFile(absolutePath, "utf-8")
}
if (fileExists && originalContent && originalContent.length > 0) {
// fix issue where claude always removes newline from the file // fix issue where claude always removes newline from the file
if (originalContent.endsWith("\n") && !newContent.endsWith("\n")) { if (originalContent.endsWith("\n") && !newContent.endsWith("\n")) {
newContent += "\n" newContent += "\n"