From d44cc99ce17b08c527ecaafb311109fe444bf2ea Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Thu, 8 Aug 2024 02:56:06 -0400 Subject: [PATCH] Fix issue where for some users fs readfile was returning undefined instead of failing --- src/ClaudeDev.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ClaudeDev.ts b/src/ClaudeDev.ts index 347ba3e..6fd6b53 100644 --- a/src/ClaudeDev.ts +++ b/src/ClaudeDev.ts @@ -419,8 +419,14 @@ export class ClaudeDev { .access(absolutePath) .then(() => true) .catch(() => false) + + // Some users reported that fs readfile would return undefined instead of failing + let originalContent: string | undefined 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 if (originalContent.endsWith("\n") && !newContent.endsWith("\n")) { newContent += "\n"