Browse Source

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

Saoud Rizwan 1 year ago
parent
commit
d44cc99ce1
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/ClaudeDev.ts

+ 7 - 1
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"